my dog learned polymorphism*
The moose likes JSP and the fly likes A JSTL doubt while assigning a variable using <c:set/> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "A JSTL doubt while assigning a variable using <c:set/>" Watch "A JSTL doubt while assigning a variable using <c:set/>" New topic
Author

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

Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

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!

Learning and Learning!-- Java all the way!
Gopakumar Naryanan
Ranch Hand

Joined: Jan 15, 2011
Posts: 72

try replacing "not eq" with either "!= " or "ne".


Thanks & Regards
Gopakumar
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Thanks , what about point 2?
Gopakumar Naryanan
Ranch Hand

Joined: Jan 15, 2011
Posts: 72

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

Joined: Jan 10, 2002
Posts: 61761
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Gopakumar Naryanan
Ranch Hand

Joined: Jan 15, 2011
Posts: 72

Yep, i too didn't notice this.
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

So this should be fine.?
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1027
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

Joined: Jan 05, 2011
Posts: 477

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

Joined: Apr 20, 2011
Posts: 21
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?
 
 
subject: A JSTL doubt while assigning a variable using <c:set/>