File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes How to get selected RadioButton value into beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to get selected RadioButton value into beans" Watch "How to get selected RadioButton value into beans" New topic

How to get selected RadioButton value into beans

shree lk

Joined: Mar 16, 2011
Posts: 14

Hi all...

I have added 3 radio buttons on my JSF from. I want to store value of selected radio button into bean so that I can display it on the JSF from. Can anybody please suggest how to get it??

Also with calender, When i display the selected date on the JSF from it shows previous day, not the selected day. But when i display in console it shows the selected day without problem..

Following is code I used in the JSF.

<h:form id="calendarForm">

<style type="text/css">

.yearRowStyle {
background-color: #A8D1E8;
color: red;
text-align: center;
font-weight: bold;
.weekRowStyle {
background-color: #D6EBFC;
.selectedDayCellStyle {
background-color: #ECD5D2;


<h3> <hutputText value="Select Date" style="color:blue"/> </h3>

<t:inputCalendar id="MyCalendar" monthYearRowClass="yearRowStyle"
value="#{calendarBean.selectedDate}" />


<t:selectOneRadio id="SR" value="SI"
style="font-weight:bold" binding="#{calendarBean.radioSelect}" >

<f:selectItem id="sel1" itemLabel="Public Holiday" itemValue="ph" />
<f:selectItem id="sel2" itemLabel="General Holiday" itemValue="gh" />
<f:selectItem id="sel3" itemLabel="Festival Holiday" itemValue="fh" />


<h3> <hutputText value="Select Holiday Type" style="color:blue"/> </h3>

<t:panelGrid columns="1" width="20%" style="color:red;"
cellpadding="0" cellspacing="5">

<t:radio for="SR" index="0"></t:radio>

<t:radio for="SR" index="1"></t:radio>

<t:radio for="SR" index="2"></t:radio>



<h:commandButton id="dateBtn" value="Submit" action="#{calendarBean.onDate}" />


AND my bean java file is..

package com.calendar.web;

import java.util.Date;

public class Calendar

Date selectedDate;
String radioSelect;

public Date getSelectedDate() {
return selectedDate;

public void setSelectedDate(Date selectedDate) {
this.selectedDate = selectedDate;

public String getRadioSelect() {
return radioSelect;

public void setRadioSelect(String radioSelect) {
this.radioSelect = radioSelect;

public String onDate()

String a=selectedDate.toString();


return "dateSelect";

Navanethan Muthusamy

Joined: Apr 06, 2009
Posts: 9


From your code what I understood is there is no like between JSP and bean in selectOneRadio tag.

Please try the following sample code:

JSP code:

<h:selectOneRadio value="#{helloWorldBacking.test}">
<f:selectItem itemLabel="Test1" itemValue="Test1" />
<f:selectItem itemLabel="Test2" itemValue="Test2" />

Bean code:

String test;

and setter getter methods for string test.


The above code work well. when I have selected first radio button i got 'Test1' in bean.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

There's a "Code" button on the Forum editor. You can use that to mark code and other pre-formatted content such as XML and make it easier to read.

You don't have to do anything complicated to get the select radiobutton value into your bean. In fact, you're already too complicated. Get rid of the "binding" on the radioButton. People use that attribute too freely (I think there's some obsolete documentation that makes them think they need to do so when they don't). Plus you didn't actually do the binding right anyway.

Just code 'value="#{calendarBean.radioSelect}"' on your radiobutton control instead of "binding=" and the "setRadioSelect" method will be invoked and passed the value of the selected button when you fire the Action Method (in other words, when you submit the form).

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: How to get selected RadioButton value into beans
It's not a secret anymore!