I’m using primefaces layout component and having difficulty with a component in an embedded form:
<p:selectOneRadio id="customRadio"
value="#{exams.examQuestions.currentQuestion.selectedAnswer}"
layout="custom">
<f:selectItem itemLabel="Option1"
itemValue="#{exams.examQuestions.currentQuestion.examentry.answer1}"
rendered="#{exams.examQuestions.currentQuestion.render_question1}"/>
<f:selectItem itemLabel="Option2"
itemValue="#{exams.examQuestions.currentQuestion.examentry.answer2}"
rendered="#{exams.examQuestions.currentQuestion.render_question2}"/>
<f:selectItem itemLabel="Option3"
itemValue="#{exams.examQuestions.currentQuestion.examentry.answer3}"
rendered="#{exams.examQuestions.currentQuestion.render_question3}"/>
<f:selectItem itemLabel="Option4"
itemValue="#{exams.examQuestions.currentQuestion.examentry.answer4}"
rendered="#{exams.examQuestions.currentQuestion.render_question4}"/>
<f:selectItem itemLabel="Option5"
itemValue="#{exams.examQuestions.currentQuestion.examentry.answer5}"
rendered="#{exams.examQuestions.currentQuestion.render_question5}"/>
<h:panelGrid columns="1">
<p:radioButton id="opt1"
for="customRadio"
itemIndex="0"
rendered="#{exams.examQuestions.currentQuestion.render_question1}"/>
<h:outputLabel for="opt1"
value="#{exams.examQuestions.currentQuestion.examentry.answer1}"
rendered="#{exams.examQuestions.currentQuestion.render_question1}"/>
<br/>
<p:radioButton id="opt2" for="customRadio"
itemIndex="1"
rendered="#{exams.examQuestions.currentQuestion.render_question2}"/>
<h:outputLabel for="opt2"
value="#{exams.examQuestions.currentQuestion.examentry.answer2}"
rendered="#{exams.examQuestions.currentQuestion.render_question2}"/>
<br/>
<p:radioButton id="opt3"
for="customRadio"
itemIndex="2"
rendered="#{exams.examQuestions.currentQuestion.render_question3}"/>
<h:outputLabel for="opt3"
value="#{exams.examQuestions.currentQuestion.examentry.answer3}"
rendered="#{exams.examQuestions.currentQuestion.render_question3}"/>
<br/>
<p:radioButton id="opt4"
for="customRadio"
itemIndex="3"
rendered="#{exams.examQuestions.currentQuestion.render_question4}"/>
<h:outputLabel for="opt4"
value="#{exams.examQuestions.currentQuestion.examentry.answer4}"
rendered="#{exams.examQuestions.currentQuestion.render_question4}"/>
<br/>
<p:radioButton id="opt5"
for="customRadio"
itemIndex="4"
rendered="#{exams.examQuestions.currentQuestion.render_question5}"/>
<h:outputLabel for="opt5"
value="#{exams.examQuestions.currentQuestion.examentry.answer5}"
rendered="#{exams.examQuestions.currentQuestion.render_question5}"/>
</p:selectOneRadio>
The backing bean exams.examQuestions.currentQuestion.selectedAnswer is not updating when I select different items, how come? If I call an update on this component “customRadio” from the same form then the backing bean updates itself however I am unable to do this outside the form. Please help!
I don’t really know what exactly do you want (cause I don’t see any forms in your sample code), but I guess your problem is that you don’t close the p:selectOneRadio after your last f:selectItem …
Please take a closer look at primefaces showcase selectOneRadio
Also if you want to update a component from another form you call the update like this
update=":formIdOfComponent:componentID"