Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jstl variable handling

 
Khushwinder Chahal
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
I want to compare a jstl variable like ${StoneAKAForm.code}
with a jsp integer variable..
Anybody have any idea .
Thanks in advance.

Khushwinder
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The need to do this is usually an indicator that JSTL isn't being used properly. JSTL is meant for scriptless JSPs where all of the heavy lifting is done with Java objects before context is ever forwarded to the JSP for markup.

If you were comparing objects, you could simply bind your scriptlet variable to request scope with request.setAttribute("name", value) and then compare the two using EL. However, in this case, you're scriptlet variable is an int which is a native type and can't be bound directly to scope without being wrapped in the Integer type.

If you really have to do this, you might be better off dereferencing ${StoneAKAForm.code} from within your scriptlet and doing the comparison there.

Maybe if you tell us why you need to compare these, someone can suggest a better strategy.
 
Khushwinder Chahal
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your reply.
But my problem is that i have to do this because of some constraints.
There is no other option.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From within your scriptlet, you could use PageContext.findAttribute to locate
the StoneAKAForm object, then call its getCode method and do the comparison there.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"khushwinder khushwinder", please check your private messages immediately.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic