• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

c:when test = .....problem

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you post the stack trace?
 
sudhakar Tadepalli
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This following doesn't work ?

 
sudhakar Tadepalli
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
>
 
sudhakar Tadepalli
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Mark says, you can use bean efine tag to place "i" into a scope.

 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<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
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic