Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

EL + Custom Tag troubles

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am trying to create a tag that does some math based on how many rows a table currently has:



It works fine when I hardcode a number for currentNumRows (like above), but I'm having trouble passing in a dynamic value. My goal is to use the tag in a <c:forEach> like this:



Keep in mind I am using JSP 1.2... so that's why I didn't simply use "${loopStatus.count}" for currentNumRows. (Ideally I don't want to use an expression.) However, I can't even get the code above to work. It gives me this error:


500 Internal Server Error
OracleJSP: oracle.jsp.parse.JspParseException: Line # 94, <drcc:emptyListRows currentNumRows="<%= pageContext.getAttribute("rowCount") %>" listSize="large" />
Error: Attribute: rowCount") is not a valid attribute name




Here's my TLD:




Thanks for any help you can give me!


Sarah
 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using single quotes around the rowCount variable


and not double quotes.

 
Marshal
Posts: 67416
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Kailash Thiyagarajan:
Try using single quotes around the rowCount variable



Knee-jerk solutions are rarely effective. That will not work because the single quote in Java denotes a character constant, not a string literal.
 
Sarah Collings
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, that would have been a good catch, but now I get a different error:

 
Bear Bibeault
Marshal
Posts: 67416
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I said.
 
Zip Ped
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear's right. Sorry for that.

Try

 
Sarah Collings
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! That worked!

Is there any way for me to pass in the value of ${loopStatus.count} in an expression without needing to create a variable first?

Something along the lines of:



I think this would at least be a little cleaner... if it can be done.
 
Bear Bibeault
Marshal
Posts: 67416
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Sarah Collings:
Thanks! That worked!



Interesting. You have found a bug in the parser. The quotes that you changed should have no effect on the JSP.
[ July 07, 2006: Message edited by: Bear Bibeault ]
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've come across that issue before while using Weblogic.
Tomcat handles the expression correctly, whether you use single or double quotes for the expression.

What server is being used?

With regards to passing the value in directly, there are ways you could do it, but I doubt they are worth the effort.

- Modify your tag to use EL rather than scriptlet expressions. Basically you would make that attribute a String, and pass it to the JSTL Expression Evaluator.
- Make the attribute the "name" of the counter, and put the pageContext.getAttribute() call inside the custom tag - that cleans up your JSP a little.

But the way you have it right now will work fine.

Hope this helps,
evnafets
 
Sarah Collings
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I actually ended up using struts to solve my problem:



For some reason I couldn't pass any kind of EL to my tag, but struts worked fine. This is much cleaner and I don't have to rely on some quotation mark bug.


Thanks for the help!

Sarah
 
Warning! Way too comfortable! Do not sit! Try reading this tiny ad instead:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic