• 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

alternate to jsp:declaration

 
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is there any alternate to

<jsp:declaration>
int count = 0 ;
</jsp:declaration>
...my html code
<jsp:scriplet>
count ++ ;
</jsp:scriptlet>
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keeping track of a incrementing count? Easy.

Do you have a copy of the JSP and JSTL specs handy? If not, you should.

Read the chapter on the EL in the JSP spec, and the section on <c:set> in the JSTL spec.
 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read jsp spec chapter on el and also the c:set part. I added following line but its not working

<c:set var="count" value="${0}"/>

<table....
<td align... class='<%= count % 2 == 0 ? "...":"..." %>' />
...more <td's>
/table>

it says count cannot be resolved.
 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read jsp spec chapter on el and also the c:set part. I added following line but its not working

<c:set var="count" value="${0}"/>

<logic:iterate ....>

<td align... class='<%= count % 2 == 0 ? "...":"..." %>' />
...more <td's>
</logic:iterate>

<jsp:scriptlet>
count ++ ;
</jsp:scriptlet>
it says count cannot be resolved. I am using this jsp:scriplet because still I dont know how to increment the value. I think I can do ${count ++} instead but still it says count cannot be resolved.
Thanks
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

<td align... class='<%= count % 2 == 0 ? "...":"..." %>' />



The JSTL and EL work with scoped variables. Scriplets with scriplet variables.

Scoped variables that you create with <c:set> are not accessible (at least not that way) to scriplets.

<jsp:scriptlet>



Are you actually using the JSP XML document notation for your JSPs?
 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Now I have replaced it as follows and its fine

class='${count % 2==0 ?"td_cellshading01":"td_cellshading01even"}'

but how do i increase this count.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using <logic:iterate> vs <c:forEach>? The latter will count the iterations for you.
 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well logic:iterate is counting iterations for me. so that is fine. but i change the value of class attribute (css style) for every other row. that is why i m using class='count % 2 == 0 ? "even row style class" : "odd row style class"'

second why i m doing it this way is because i m just mantaining this code. It is working fine. Why i m doing this is because i think it would be better and this way i could learn EL and also jstl to certain extent because normally i m used to of using struts tags.

Thanks
Imad
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a worthy goal, but be aware that mixing scriptlets. JSTL, Struts tags and EL all in the same page can be rather messy as they don't interoperate all that well.
 
We find this kind of rampant individuality very disturbing. But not this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic