Set up default radio button h:selectOneRadio on JSF - jsf

I have this code
<h:selectOneRadio value="#{MyBean.valueAttr}" >
<f:selectItem itemLabel="Button1"/>
<f:selectItem itemLabel="Button2" />
<f:selectItem itemLabel="Button3" />
</h:selectOneRadio>
I wanted to know if there is a way to set up the Button3 as the chosen button (default) initially.
Thanks

Add itemValue attribute to your f:selectItem and set default value of #{MyBean.valueAttr} in your bean

Related

JSF Bootsfaces b:selectOneMenu itemValue = null displaying the label value instead

I am using Bootsfaces 1.0.2. The code below, of course, is inside a form. Notice the first selectItem has an itemValue=#{null}. When the page loads, the inputText field with id='test' shows as blank. I then change the dropdown to any other value and the value displays correctly. When I go back to the first option in the drop down with null value, the inputText field displays "-- Seleccione --". What I would expect to see is blank (NULL), right? Or am I missing something here?
<b:selectOneMenu value="#{wCPVMController.wcpvm.tipo_v}"
id="categoriaVehiculo" label="CategorĂ­a de VehĂ­culo"
required="true" process="#this" update="containerRiesgos test"
onchange="ajax:wCPVMController.getRiesgosOpcionales()">
<f:selectItem itemLabel="-- Seleccione --" itemValue="#{null}" />
<f:selectItem itemLabel="Liviano" itemValue="L" />
<f:selectItem itemLabel="Pesado" itemValue="P" />
<f:selectItem itemLabel="Autobus" itemValue="A" />
<f:selectItem itemLabel="Motocicleta" itemValue="M" />
<f:selectItem itemLabel="Otro" itemValue="O" />
</b:selectOneMenu>
<b:inputText id="test" value="#{wCPVMController.wcpvm.tipo_v}"></b:inputText>
Write instead itemValue=""
See example here:
https://showcase.bootsfaces.net/forms/selectOneMenu.jsf

Default value from a list not passed to the next page while using <p:selectOneMenu> in jsf datatable

Default value from a list not passed to the next page while using in jsf datatable,all the default values get replaced with null value for all the items not selected in the datatable
You need to save the list using the managedbean in session scope.
Heading ##
<!-- <h:outputText value="#{rule.userAlertCategory.label}"/> -->
<p:selectOneMenu id="catCombo" value="#{rule.userAlertCategory}" style = "width:100%" converter="srUserAlertCategorySelectItemsConverter">
<p:ajax event="change" update="subCatCombo" listener="#{newAlertSetupController.onCategoryChanged}" process="#this"/>
<f:selectItem itemLabel="Select One" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{newAlertSetupController.userAlertCategoryList}" var="cat" itemLabel="#{cat.label}" itemValue="#{cat}"/>
</p:selectOneMenu>
</p:column>

How to set radio button as true bydefault

I want to make my radio button bydefault as true. My sample code is given below:
<p:selectOneRadio value="#{empcategoryBean.dto.is_Esi}" disabled="#{empcategoryBean.sta}" >
<f:selectItem itemLabel="Yes" itemValue="1"/>
<f:selectItem itemLabel="No" itemValue="0"/>
</p:selectOneRadio>
go the following link:-
JSF set default value Radio Button h:selectOneRadio
Set value in your backing bean with the desired default value. For example if you want "1" as default:

Radio button not passing value when submitted

I have an UI where I use a radio button to select the gender. However, when I press submit to store the data to the database I only ever get a null value
This is the code:
<p:selectOneRadio id="gender"
value="{formBean.number}"
layout="grid"
columns="2"
required = "True"
requiredMessage="#{bundle.requiredGender}">
<f:selectItem itemLabel="#{bundle.labelMale}" itemValue="Male"/>
<f:selectItem itemLabel="#{bundle.labelFemale}" itemValue="Female" />
</p:selectOneRadio>
What have I missed out?

changing values of selectOneMenu in JSF

I am new to JSF and i am stuck at one place. I have one dropdown list which contains two items.
Bank
Cash
Now, if I select bank the other dropdown should populate items related to bank and if I select cash, cash items should be shown in 2nd dropdown.
How to do it in JSF? Where I have to make changes?
Any help will be highly appreciated.Thanks
Well you can use primefaces to improve jsf development
<p:selectOneMenu id="cboCountries" value="#{beanCountries.ValueSelected}" effect="fade">
<f:selectItem itemLabel="Select Country" itemValue="-1" /> //a default value
<f:selectItems value="#{beanCountries.listOfCountries}" var="countries" itemLabel="#{countries.name}" itemValue="#{countries.id}"/>
<p:ajax event="change" update="cboCities" listener="beanCountries.listCities()"/> //notice "update" refresh an especific DOM Element of an especific ID
</p:selectOneMenu>
<p:selectOneMenu id="cboCities" value="#{beanCities.ValueSelected}" effect="fade">
<f:selectItem itemLabel="Select City" itemValue="-1" /> //a default value
<f:selectItems value="#{beanCities.listOfCities}" var="cities" itemLabel="#{cities.name}" itemValue="#{cities.id}"/> //this is when you want to put elements from DB or from an Array
</p:selectOneMenu>
" is a special mark from primefaces, the event = "change" will invoke the you select an element from the first "ComboBox" then the property update will refresh the second comboBox, and the property "listener" will do the logical action of what you want to do, in this case the method "listCities()" will fill "listOfCities" with values from DB o Arrays.
So in jsf without primefaces will be like this:
<h:form>
<h:selectOneMenu value="#{beanCountries.ValueSelected}">
<f:selectItem itemLabel="Select Country" itemValue="-1" /> //a default value
<f:selectItems value="#{beanCountries.listOfCountries}" var="countries" itemLabel="#{countries.name}" itemValue="#{countries.id}"/>
</h:selectOneMenu>
<h:selectOneMenu id="cboCities" value="#{beanCities.ValueSelected}">
<f:selectItem itemLabel="Select City" itemValue="-1" /> //a default value
<f:selectItems value="#{beanCities.listOfCities}" var="cities" itemLabel="#{cities.name}" itemValue="#{cities.id}"/> //this is when you want to put elements from DB or from an Array
</h:selectOneMenu>
<h:commandButton value="Submit" action="beanCountries.listCities()"/>
</h:form>
this way is with a button (in jsf) and the action property will execute a java Method and then refresh the page. also this could be made by "ValueChangeListener" property of the selectOneMenu component

Resources