• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting value of radio button to JSTL c:if

 
Drew Jonas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have

<h:selectOneRadio id= "gSelect">
    <f:selectItem id= "one" itemlabel="abc" itemValue ="ABC"/>
    <f:selectItem id= "two" itemlabel="xyz" itemValue ="XYZ"/>
</h:selectOneRadio>

c:if test ="when radio selection equals abc"
do stuff

need help with the c:if test
 
Dave Tolls
Ranch Hand
Posts: 2207
20
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you expecting this if test to be done?
 
Drew Jonas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to check to see which radio button was check and grab that value to be used for a property in a bean on submit
 
Drew Jonas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The if test is on same jsp as radio
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15690
73
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
c:if is probably not the best way to do whatever exactly you want to do. In fact, it's better to not use the JSTL tag libraries in JSF at all (certainly not if you are using a newer JSF version).

Why not bind the value of the selectOneRadio component to a property of one of your beans:

That way, whenever the page is submitted, the 'someProperty' property of bean 'myBean' will automatically be set to the selected radio button value ("ABC" or "XYZ"). If you need more logic, you can put that in your Java code in beans instead of in your Facelets pages. Beans are the right place to program business logic.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!