Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to declare a numeric type variable using EL  RSS feed

 
Mukhi Vla
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • 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
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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 ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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?

 
Paul Clapham
Sheriff
Posts: 22480
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Kris Schneider
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!