Nesting a h:selectOneRadio inside another h:selectOneRadio 's f:selectitem - jsf

I want to create a group of radio buttons inside an option of another radio button.
It has to look like this.
Radio Title1
O Yes
Radio Title2
O Yes
O No
O No
When I try the following code the items are rendered as two rows of a table, but when i keep another component inside this selectone radio item, it keeps out of the table, So I am not able to achieve what I want.
<h:selectOneRadio id="reportDestination" layout="pageDirection">
<f:selectItem itemLabel="Yes" itemValue="Yes" />
<h:selectOneRadio layout="pageDirection">
<f:selectItems itemLabel="Yes" itemValue="Yes"/>
<f:selectItems itemLabel="No" itemValue="No"/>
</h:selectOneRadio >
<f:selectItem itemLabel="No" itemValue="No" />
</h:selectOneRadio>
Is there anyway to do it?
Any input is appreciated like a reference or a logic or anything.
Thanks in advance.

Related

How enable/disable <p:tab> without update form?

I have a big <h:form>, with a <p:tabView> with 3 <p:tab>
I want to enable/disable one <p:tab> based on <p:selectOneRadio> click.
How can I achieve this without updating the entire form?
<p:selectOneRadio id = "pessoa" required = "true"
value="#{myBean.typeChecked}" valueChangeListener="#{myBean.checkTypeSelec}">
<f:selectItem itemLabel="item 1" itemValue="PF" />
<f:selectItem itemLabel="item 2" itemValue="PJ" />
<p:ajax event="click" update="???" execute="#this"/>
</p:selectOneRadio>
<p:tab title="History" id="historyTab" disabled="#{myBean.historyDisabled}">...
I dont wanna update entire form because I dont wanna loose other inputs data

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

selectOneRadio set value as index of selected item

I want my p:selectOneRadio to have value of index of selected radio button.
For example, rows in p:dataTable can be aware of their index using attribute rowIndexVar="rowIndex".
So my question is, can individual radio buttons in p:selectOneRadio be aware of their index? Then i could do something like this
<p:selectOneRadio itemIndexVar="index" value="#{bean.selectedIndex}">
<f:selectItems value="#{bean.items}" var="item" itemValue="#{index}" itemLabel="#{item.label}" />
</p:selectOneRadio>
EDIT:
If i specify items manually, i can indeed set itemValue to represent index of that item, see below.
<p:selectOneRadio id="options" value="#{formBean.selectedIndex}">
<f:selectItem itemLabel="First item has index 0" itemValue="0" />
<f:selectItem itemLabel="Second item has index 1" itemValue="1" />
<f:selectItem itemLabel="Third item has index 2" itemValue="2" />
</p:selectOneRadio>
This would make my p:selectOneRadio to have value corresponding to index of selected radiobutton.
I want to do the same thing, but using f:selectItems tag instead of multiple f:selectItem

SelectOneMenu with Delete link

I am wondering is there a way i can add delete() in the select one menu, so that the user either can select one from the menu or delete the record right from there itself. So far i have normal select one menu, i have a method called "#{statusReport.deleteTieckt}" method. I just wondering how to add that to the below select one menu.
<ice:selectOneMenu value="#{statusReport.projectDetID}"
style="width: 350px;" partialSubmit="true"
onchange="this.form.submit()" immediate="true"
valueChangeListener="#{statusReport.retrieveReport}">
<f:ajax disabled="true"></f:ajax>
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{statusReport.listOfProjectDetail}"
var="projectBO"
itemLabel="#{projectBO.projectDtObj.pname} #{projectBO.startDate} - #{projectBO.endDate}"
itemValue="#{projectBO.pdetailId}" noSelectionValue="true" />
</ice:selectOneMenu>

Resources