| Author |
c:when test = .....problem
|
sudhakar Tadepalli
Ranch Hand
Joined: Dec 27, 2001
Posts: 130
|
|
Can some one modify this logic ?. I am getting error. <logic:iterate indexId="i" id="collection" name="dataForm" property="collection"> <c:choose> <c:when test ="${[i.intValue()%2 == 0]}"> <tr> </c:when> <c therwise> <tr bgcolor=#C0C0C0> </c therwise> </c:choose>
|
 |
Kerry Wilson
Ranch Hand
Joined: Oct 29, 2003
Posts: 251
|
|
|
Could you post the stack trace?
|
http://www.goodercode.com
SCJP 1.4
|
 |
sudhakar Tadepalli
Ranch Hand
Joined: Dec 27, 2001
Posts: 130
|
|
Here is the error displayed in JSP. Validation error messages from tag library c tag = 'when' / attribute = 'test': An error occurred while parsing custom action attribute "test" with value "${[[i.intValue()%2] == 0]}": Encountered "[", expected one of [, , , "true", "false", "null", "(", "-", "not", "!", "empty", ]' I hope u understood what I am doing. Trying to display two colors in a table based on the "i%2 ==0" value
|
 |
Cendy Nguvy
Ranch Hand
Joined: May 25, 2005
Posts: 37
|
|
This following doesn't work ?
|
 |
sudhakar Tadepalli
Ranch Hand
Joined: Dec 27, 2001
Posts: 130
|
|
Cindy , That does not work either. But I am able to print using c ut tag for testing purpose. "i" is IndexId of an logic iterator. Please see above code.
|
 |
Marc Peabody
pie sneak
Sheriff
Joined: Feb 05, 2003
Posts: 4725
|
|
The problem is that the logic tag is saving "i" as a variable and JSTL only looks in the scopes for variables. Using html-el:logic might work. Or there might be a bean tag (define?) that could place it into a scope. By the way, this might be simpler with a simple if instead of choose/when/otherwise: <tr <c:if test='???'>bgcolor="#C0C0C0"</c:if> >
|
A good workman is known by his tools.
|
 |
sudhakar Tadepalli
Ranch Hand
Joined: Dec 27, 2001
Posts: 130
|
|
Some one suggested me to use c:if, I just thought to try, But I gave up, Don't want to make life so complicated This works fine for me. Thank you all anyway. <logic:iterate indexId="i" id="collection" name="dataForm" property="collection"> <%if (i.intValue()%2 == 0) {%> <tr> <%}else{%> <tr bgcolor=#C0C0C0> <%}%>
|
 |
Cendy Nguvy
Ranch Hand
Joined: May 25, 2005
Posts: 37
|
|
As Mark says, you can use bean efine tag to place "i" into a scope.
|
 |
Marc Peabody
pie sneak
Sheriff
Joined: Feb 05, 2003
Posts: 4725
|
|
Originally posted by Cendy Nguvy: As Mark says, you can use bean  efine tag to place "i" into a scope.
Apparently my other casual suggestion was too important to give any attention to the actual solution. :roll:
|
 |
sudhakar Tadepalli
Ranch Hand
Joined: Dec 27, 2001
Posts: 130
|
|
Marc and Cindy, I tried again but no luck <logic:iterate indexId="i" id="collection" name="templateForm" property="collection"> <bean efine id="ind" name="collection" property="i"/> <c:if test ="${ind.intValue()%2 == 0}"> <tr> </c:if> <tr bgcolor=#C0C0C0> Error on JSP : Validation error messages from tag library c tag = 'if' / attribute = 'test': An error occurred while parsing custom action attribute "test" with value "${ind.intValue()%2 == 0}": Encountered "(", expected one of ["}", ".", ">", "gt", "<", "lt", "==", "eq", "<=", "le", ">=", "ge", "!=", "ne", "[", "+", "-", "*", "/", "div", "%", "mod", "and", "&&", "or", "||"]' Thanks Sudhakar
|
 |
Marc Peabody
pie sneak
Sheriff
Joined: Feb 05, 2003
Posts: 4725
|
|
<logic:iterate indexId="i" id="collection" name="templateForm" property="collection"> <bean:define id="ind" name="i"/> <c:if test="${ind%2 == 0}">
|
 |
Marc Peabody
pie sneak
Sheriff
Joined: Feb 05, 2003
Posts: 4725
|
|
Hmm, I just tried this without the bean efine and it also worked. <logic:iterate indexId="i" id="collection" name="templateForm" property="collection"> <c:if test="${i%2 == 0}">
|
 |
sudhakar Tadepalli
Ranch Hand
Joined: Dec 27, 2001
Posts: 130
|
|
Yahooooo...Thanks Marck it works now. It works without bean defined alo. I think the problem with intValue() method. Thanks alot...another thread got fixed Sudhakar
|
 |
 |
|
|
subject: c:when test = .....problem
|
|
|