This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes c:if tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "c:if tag" Watch "c:if tag" New topic
Author

c:if tag

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

How would you construct such a test if you were writing a Java if statement?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

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.
trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
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
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
you coiuld use the <c:choose> tag. It has c <ctherwise> sub tag
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

A link to the JSP Specification can be found in the JSP FAQ.
trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
Originally posted by Michael Ku:
you coiuld use the <c:choose> tag. It has c <ctherwise> 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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

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 ]
 
 
subject: c:if tag
 
Similar Threads
Populate Table Rows With Data from AJAX
Help need in query
defining static araylist in stateless session ejb
Extract values from a string
Struts ActionMessage not displaying multiple dynamic values