开发者

Doubts when using radio button group(JSF 2.0)

I have a variable in my backing bean of type int:

private int myVariable;

//Get and set methods

What i want is to give to the variable above a different value depending on the radio button that is selected.

<开发者_运维问答;h:selectOneRadio
            id="myComponent" value="#{myBackingBean.myVariable}">
                    <f:selectItem itemValue="7" itemLabel="Text 1" />
                    <f:selectItem itemValue="12" itemLabel="Text 2" />
                    <f:selectItem itemValue="8" itemLabel="Text 3" />                       
</h:selectOneRadio>

How can myVariable have value 7 if the first item is selected, 12 if the second and 8 if the third?

Can i do this by changing my setter method?

How?

What is the easiest way?


We have converter exactly for this purpose. Here it is demonstrated


The code is fine. You don't need to do anything else. JSF/EL has already builtin converters (coercions) for standard value types boolean, integer, long, float and double. If you have a problem with it, it definitely lies somewhere else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜