This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

convert scriptlet code into Expression language or JSTL

 
jaid shaik
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am working on jsp pages,
in jsp pages i need to change scriptlets to JSTL tags or Expression language

I am new to jstl
how to change below code in to JSTL





Thanks

 
Gopakumar Naryanan
Ranch Hand
Posts: 72
Eclipse IDE Hibernate Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jaid shaik wrote:Hi,



Looks like you are checking whether 'heightUnit' is not NULL and heightUnit equals "meters/cm" ..

If what i understood is correct, you can do it as follows:


Hope the above code will work .
 
jaid shaik
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi gopakumar,

Thanks for reply....

can i use like this......




please let me know....

thanks
 
Gopakumar Naryanan
Ranch Hand
Posts: 72
Eclipse IDE Hibernate Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.. It won't work if you write so.

I meant you can directly write like this :

 
Stefan Evans
Bartender
Posts: 1755
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If all the ValidatorUtil is doing is checking for null explicitly, then that substitution is ok.
EL also handles nulls better than regular java, so the null check is not necessary in the EL expression.
So my interpretation would be: ${heightUnit eq 'meters/cm' ? true : false}



These examples result in:
false - val1 is not equal to meters/cm
true - val2 is equal
false - val3 is null (not set as an attribute on the page)


On the other hand if Validator is doing more than a simple null check (e.g. removing all spaces from a string and THEN checking for null/empty) then you need to duplicate that functionality, or call it via an EL function. You can quite easily invoke static functions like this from EL.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic