this question has answer here:
i have bean called question lot of alternatives -->
question have 1:n alternative.
i have page lot of question, like:
page have 1:n question
i need create xhtml page showing amount of questions , alternatives, this:
<c:foreach var="questaocurso" items="#{cursandomb.paginaatualprova.questoescurso}"> <h:outputtext value="#{questaocurso.questao.texto}" /> <br /> <h:selectoneradio style="font-weight: normal" value="#{cursandomb.alternativasescolhida}" layout="pagedirection"> <f:selectitems value="#{questaocurso.questao.alternativaspreenchidas}" var="c" itemvalue="#{c}" itemlabel="#{c.texto}" /> </h:selectoneradio> <br /> <br /> </c:foreach>
the problem don't know how can set each choose alternative in list in managedbean. can't create 1 variable each question, because dynamic , don't know amount of questions in design-time.
solved:
i used map in radiobutton, see:
<h:selectoneradio value="#{cursandomb.alternativasescolhidas[questaocurso]}" converter="entityconverter" layout="pagedirection"> <f:selectitems value="#{questaocurso.questao.alternativaspreenchidas}" var="c" itemvalue="#{c}" itemlabel="#{c.texto}" /> </h:selectoneradio>
first, must not mix render-time (e.g. f:selectitems, h:inputtext ...) , build-time tags (jstl tags, f:actionlistener, ui:include ... ), more understanding of view build time , render time concepts , how works please take balusc's answer: jstl in jsf2 facelets... makes sense?
so imo thing replace c:foreach
tag ui:repeat
this:
<ui:repeat var="questaocurso" value="#{cursandomb.paginaatualprova.questoescurso}"> <h:outputtext value="#{questaocurso.questao.texto}" /> <br /> <h:selectoneradio style="font-weight: normal" value="#{cursandomb.alternativasescolhida}" layout="pagedirection"> <f:selectitems value="#{questaocurso.questao.alternativaspreenchidas}" var="c" itemvalue="#{c}" itemlabel="#{c.texto}" /> </h:selectoneradio> <br /> <br /> </ui:repeat>
the value
attribute of ui:repeat tag is:
the name of collection of items tag iterates over. collection may list, array, java.sql.resultset, or individual java object. if collection null, tag nothing.
so can use list
of object in value
in case list of question objects, , in question bean can include list
of answers (while answer
may bean).