Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EL + Custom Tag troubles  RSS feed

 
Sarah Collings
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
 
Zip Ped
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.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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 ]
 
Stefan Evans
Bartender
Posts: 1836
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!