Forums Register Login

c:if tag

+Pie Number of slices to send: Send
I want to check if the value of the variable equals any of the possible 4 values like val1,val2,val3 , val4 i.e. if the value is other than val4 then format the page in A format else format it in B format.

Thanks,
Trutpi
+Pie Number of slices to send: Send
How would you construct such a test if you were writing a Java if statement?
+Pie Number of slices to send: Send
 

Originally posted by Bear Bibeault:
How would you construct such a test if you were writing a Java if statement?



OK I would write something like below:

if(name == val1 || name== val2|| name==val3){
//format jsp in first way
}else{
//format JSP in second way
}

I am not sure how to combine the or statement using the JSTL tags also is there in else?

Thanks,
Trupti
+Pie Number of slices to send: Send
If you are writing JSPs you need to have a copy of the JSP spec open on your desk. The section on the EL will let you know what operators exist that you can use.
+Pie Number of slices to send: Send
 

Originally posted by Bear Bibeault:
If you are writing JSPs you need to have a copy of the JSP spec open on your desk. The section on the EL will let you know what operators exist that you can use.



That is the first thing I would do. I tried searching the google and other resources but could not find how to use "or" in the JSTL <c:if> tag.

Thought about posting it on Javaranch.

Thanks,
Trupti
+Pie Number of slices to send: Send
you coiuld use the <c:choose> tag. It has c <c:otherwise> sub tag
+Pie Number of slices to send: Send
A link to the JSP Specification can be found in the JSP FAQ.
+Pie Number of slices to send: Send
 

Originally posted by Michael Ku:
you coiuld use the <c:choose> tag. It has c <c:otherwise> sub tag



But Can I use the "or" condition within <c:choose>

As I do not want to repeat the same code within different <c:choose> condtions.

In Java my condition would be
if(name=='A1'|| name=='A2'||name=='A3')
{
//format in style 1
}
else{
//format in style 2
}


Thanks,
Trupti
+Pie Number of slices to send: Send
The idiom for an if-then-else in the JSTL:



It is completely independent of the what operators you use within the condition expression.
[ August 13, 2007: Message edited by: Bear Bibeault ]
Note to self: don't get into a fist fight with a cactus. Command this tiny ad to do it:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1582 times.
Similar Threads
Help need in query
Populate Table Rows With Data from AJAX
defining static araylist in stateless session ejb
Extract values from a string
Struts ActionMessage not displaying multiple dynamic values
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:57:57.