Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A JSTL doubt while assigning a variable using <c:set/>

 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All ,
Im trying to use a scoped variable in my jsp to help with formatting of the code .However, I think Im doing something wrong at two points , however cant figure out what exactly im doing wrong.


Im trying to set a scoped variable v to a value 0 initially and then trying to print output in a particular manner if it does not match the value of npumpinternalid, and at the end of that <c:when > loop I reassign the value of npumpinternalid to v , to help with formatting .
Right now , Im facing an error at Point 1.
Saying.

org.apache.jasper.JasperException: /pages/test.jsp(463,9) "${v not eq cl.npumpinternalid}" contains invalid expression(s): javax.el.ELException: Error Parsing: ${v not eq cl.npumpinternalid}
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:198)

Also , I would like to know whether what Im doing to reassign 'v' at Point 2 is good enough too.

Thank you for your time!
 
Gopakumar Naryanan
Ranch Hand
Posts: 72
Eclipse IDE Hibernate Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try replacing "not eq" with either "!= " or "ne".
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks , what about point 2?
 
Gopakumar Naryanan
Ranch Hand
Posts: 72
Eclipse IDE Hibernate Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think <c:set var="v" value="0" scope="file"/> statement should be written prior to <c:forEach> loop.
As you are assigning the variable 'v' to '0' at the first step in each iteration, it won't be useful reassigning the value.

Try it and let me know the update.

Thanks
Gopakumar
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
scope="file"

Huh?

The question cannot be answered without knowing what you are trying to accomplish with the <c:set>. It looks completely superfluous as is.
 
Gopakumar Naryanan
Ranch Hand
Posts: 72
Eclipse IDE Hibernate Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, i too didn't notice this.
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So this should be fine.?
 
Stefan Evans
Bartender
Pie
Posts: 1670
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Logic looks alright.
From what I can tell you want to print a different heading row when the cl.npumpinternalid changes.


Suggestions
- use a better variable name than 'v'. 'previousValue' makes it clearer to understand what is happening.
- DRY: Don't repeat yourself. Seperate out the bit that is common
- you missed out the <tr> tags from the code. They should presumably be within the forEach loop, and presumably use the style variable you were setting, so you may need to initialise that value too.



 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stefan , yes thats precisely what Im trying to do! .
Thanks a lot for the pointers.Will get back if there are any issues!
 
aatish pandya
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Stephan,

I have posted -

Myself wrote -
Java Forums > JSP > "Not able to execute code for forEach loop in EL"



What I am trying to do is just run the forEach Loop to display Array/LinkedList/Object variables of simple data types String and int.

However, nothing is displayed on the browser!

Maybe some more steps are required in the JSP File to display the forEach Loop!

For your convenience I am re-writting the code for Bean File and JSP File -

JSP File -



The Data can be in a Bean File in the form of an Array/List/LinkedList or Object as may be the case!

Eg I. <Bean_File_Array.java>


Eg.II <Bean_File_Linked_List.java>


Eg.III <Bean_File_Object.java>


What is the way around to display the contents of these 3 Files using EL for the forEach. I tried to read your forEach Example, but I could not understand, so I have given my example!

Maybe I am missing something in the JSP file other than whatever code I have written for the forEach loop?
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic