JSF + Primefaces <p:selectOneRadio inside Datatable and Pagination

Asked

Viewed 270 times

1

<p:dataList value="#{simuladoBean.questoes}" var="q" type="unordered"
                rowIndexVar="qi" itemType="none" paginator="true" rows="1"
                styleClass="paginated">

      <h:panelGrid columns="2" style="color:#000;"
                        rendered="#{q.tipo == simuladoBean.certoErrado}">
                        <p:outputLabel for="resposta" value="Resposta: " />
                        <p:selectOneRadio id="resposta" value="#{simuladoBean.resposta}"
                            style="color:black;width:auto;">
                            <p:ajax listener="#{simuladoBean.processaResposta}" />
                            <f:selectItem itemLabel="Certo" itemValue="Certo | #{q.id}" />
                            <f:selectItem itemLabel="Errado" itemValue="Errado | #{q.id}" />
                        </p:selectOneRadio>
     </h:panelGrid>
            </p:dataList>

My Managedbean is like @Named and @ViewScoped.

import javax.inject.Named;
import javax.faces.view.ViewScoped;

The code works normally though, when moving from one page to another (Pagination), when I return to the previous page the radiobutton is cleared, the ViewScoped just doesn’t work for the SelectOneRadio. How do I keep the Selectoneradio as viewScoped, so that if you mark for example right on the first page when passing to the second and returning to the first the 'right' is still marked?

  • you need to leave Viewscoped even? Maybe Sessionscoped will solve your problem.

  • Even with the Sessionscoped it doesn’t work. All Managedbean attributes are staying in the view scope, just this <f:selectoneRadio that is not.

  • Maroni tempted me to a detail, did you see the import? in my classes I usually import the "import javax.faces.bean.Viewscoped;" tries to change the import, leaving Viewscoped even and tell me if it worked. Hugs

  • Yes, the Imports are correct, I left them there on the question. import javax.inject.Named; import javax.faces.view.Viewscoped;

  • Exactly, in my last comment I gave the idea to change the import that is "javax.faces.VIEW.Viewscoped" to "javax.faces.BEAN.Viewscoped"

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.