You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Caroline Jen <ji...@yahoo.com> on 2005/10/07 19:07:38 UTC

Want a Default Selected Radio Button. What to Do?

I want to show a default selected radio button when
the web page is loaded for the first time.  Normally,
I create a set of radio buttons this way:

[code]
<h:selectOneRadio
value="#{dataManagementBean.dataTransferType}"
layout="pageDirection" >
     <f:selectItems
value="#{dataManagementBean.dataTransferTypeItems}"/>
</h:selectOneRadio>
[/code]

To show a default selection, I can add a statement in
my backing bean
 
[code]
String defaultSelectedDataTransferType =
"imports";[/code] 
where "imports" is the value of one of my buttons. 
Then, I display the web page this way:

[code]
<h:selectOneRadio
value="#{dataManagementBean.defaultSelectedDataTransferType}"
layout="pageDirection" >
     <f:selectItems
value="#{dataManagementBean.dataTransferTypeItems}"/>
</h:selectOneRadio>
[/code]

The problem is that whatever the radio button that
users actually select, its value is assigned to the
[b]defaultSelectedDataTransferType[/b].

I want the [b]dataTransferType[/b] gets the value of
the button that users select.  What should I do?


		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

Re: Want a Default Selected Radio Button. What to Do?

Posted by Mathias Brökelmann <mb...@googlemail.com>.
put the default value into the inital value of dataTransferType:

String _dataTransferType = DEFAULT_VALUE;

public String getDataTransferType()
{
  return _dataTransferType;
}

public void setDataTransferType(String value)
{
  _dataTransferType = value;
}

2005/10/7, Caroline Jen <ji...@yahoo.com>:
> I want to show a default selected radio button when
> the web page is loaded for the first time.  Normally,
> I create a set of radio buttons this way:
>
> [code]
> <h:selectOneRadio
> value="#{dataManagementBean.dataTransferType}"
> layout="pageDirection" >
>      <f:selectItems
> value="#{dataManagementBean.dataTransferTypeItems}"/>
> </h:selectOneRadio>
> [/code]
>
> To show a default selection, I can add a statement in
> my backing bean
>
> [code]
> String defaultSelectedDataTransferType =
> "imports";[/code]
> where "imports" is the value of one of my buttons.
> Then, I display the web page this way:
>
> [code]
> <h:selectOneRadio
> value="#{dataManagementBean.defaultSelectedDataTransferType}"
> layout="pageDirection" >
>      <f:selectItems
> value="#{dataManagementBean.dataTransferTypeItems}"/>
> </h:selectOneRadio>
> [/code]
>
> The problem is that whatever the radio button that
> users actually select, its value is assigned to the
> [b]defaultSelectedDataTransferType[/b].
>
> I want the [b]dataTransferType[/b] gets the value of
> the button that users select.  What should I do?
>
>
>
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
>


--
Mathias