Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

c:if tag

 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65110
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would you construct such a test if you were writing a Java if statement?
 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65110
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you coiuld use the <c:choose> tag. It has c <ctherwise> sub tag
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65110
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A link to the JSP Specification can be found in the JSP FAQ.
 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65110
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic