• 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

How to declare a numeric type variable using EL

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


I want to create a variable that holds integer value and want to use increment operation on that variable.

Can anyone help me this this?

Thanks
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
EL is used to read things, not to change them. Where and when do you want to increment that variable ?
 
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
Yeah, this has red flags all over it. Make sure that what are you trying to do is appropriate for the view.

If you want to increment over a count, check out the <c:forEach> JSTL tag.

If you really do need to create a scoped variable (be sure that it's appropriate):
 
Mukhi Vla
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
below is my code piece.

<c:forEach var="attribute" items="${compareAttributes}" varStatus="item">
<c:if test="${attribute.displayName != 'Price'}">
<tr class="<c:if test="${item.count % 2 == 1}">even</c:if>">
<th class="attribute dotted-right"><strong>${mn:htmlFormat(attribute.displayName)}</strong></th>
<td> something </td>
</tr>
</c:if>
</c:forEach>

I am printing the rows in Zebrastips, for that i am doing ' if item.count%2==1' then apply cssClass ' even'.
But i am skipping one row from the retrieved list. It is in row 5. so my 4th and 6th rows come one after the other(5th row is skipped).here when i use 'item.count%2' , since 4th and 6th rows are even i am getting those two rows in same background color. to get rid of this i am trying to declare a variable on which i can do increment operation and use it in place of item.count.

I tried <c:set var="evenCount" value="${0}" /> (as replied in the above thread) and then <c:if test="${evenCount++ % 2 == 1}">
But this did not help me.

What i did was :
<c:set var="evenCount" value="${0}" />
<c:forEach blah blah.....>
<c:set var="evenCount" value="${evenCount+1}" /> and then <c:if test="${evenCount % 2 == 1}">
-----
---
</c:forEach>

is working fine.

Now my question is , how can i make use of increment/decrement (++,--) operators in EL?


 
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
Please UseCodeTags. I will not look at unformatted code.
 
Mukhi Vla
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
below is my code piece.


I am printing the rows in Zebrastips, for that i am doing ' if item.count%2==1' then apply cssClass ' even'.
But i am skipping one row from the retrieved list. It is in row 5. so my 4th and 6th rows come one after the other(5th row is skipped).here when i use 'item.count%2' , since 4th and 6th rows are even i am getting those two rows in same background color. to get rid of this i am trying to declare a variable on which i can do increment operation and use it in place of item.count.

I tried <c:set var="evenCount" value="${0}" /> (as replied in the above thread) and then <c:if test="${evenCount++ % 2 == 1}">
But this did not help me.

What i did was :


is working fine.

Now my question is , how can i make use of increment/decrement (++,--) operators in EL?

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mukhi Sadana wrote:Now my question is , how can i make use of increment/decrement (++,--) operators in EL?



And why do you ask that? You already know how to increment a variable in EL, you have posted code demonstrating that. I don't see what your problem is.
 
Mukhi Vla
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got the solution. but i want to use ++ operator, as it is supported by EL. I want to know how i can use it.
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mukhi Sadana wrote:...i want to use ++ operator, as it is supported by EL.



The increment operator is not part of the EL.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic