tags:

views:

61

answers:

1

I have used Tomahawk <t:selectOneRadio> in my jsf page. I have reserved one boolean value for each radio button in my back bean, but I have a problem with linking the component to the backing bean. How must I link the component to the backing bean?

Is my data model in backing bean wrong?

This is my code:

<t:radio index="0" for="select"></t:radio>
<t:selectOneRadio id="select" layout="spread">
<f:selectItem itemLabel="Every" itemValue="Every" />
<h:inputText id="days" /> days 
<br />
<t:radio index="1" for="select"></t:radio>
<f:selectItem itemLabel="Every Weekday"
itemValue="Every Weekday" />
</t:selectOneRadio>
A: 

Use the value attribute.

<t:selectOneRadio value="#{bean.selectedItem}">

That said, the component is not used the correct way in your code. Only the selectitems should go in the component and the t:radio index should start with 0. Here's a rewrite:

<t:selectOneRadio id="frequency" value="#{bean.frequency}" layout="spread">
    <f:selectItem itemLabel="Every" itemValue="Every" />
    <f:selectItem itemLabel="Every weekday" itemValue="Every weekday" />
</t:selectOneRadio>

<t:radio for="frequency" index="0" /><h:inputText value="#{bean.days}" /> days
<br />
<t:radio for="frequency" index="1" />

In the bean you need the following:

private String frequency;
private Integer days;
// Add/generate getters and setters.

Depending on the selection, the selected itemValue will be set as frequency (which can thus be either "Every" or "Every weekday") and the entered days will be set as days.

BalusC