The p: dataTable is not paging

1

Te a page that receives a param.

    <f:metadata>
        <f:viewParam name="id" value="#{MyBean.MyObject.id}" />
        <f:event type="preRenderView" listener="#{MyBean.exibir}" />
    </f:metadata>

    <c:set var="myobject" value="#{MyBean.MyObject.id}" scope="session"/>

    <h:form id="tabelaLancamentoid">
                <p:dataTable id="dataid" var="data" value="#{MyBean.All}"
                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
                 paginator="true" rows="10" style="margin-bottom:20px">

                  <p:column headerText="Nome">
                  <h:outputText value="#{data.nome} " />
                  </p:column>

                </p:dataTable>
    </h:form>

My MyBean

@Inject
FansubberDao dao;

private MyObjetc myObject = new MyObjetc(); 

    FacesContext facesContext = FacesContext.getCurrentInstance();
    HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(true);

public void exibir(){
    if(myObject.getId()!=null)
        myObject = dao.getMyObjetc(myObject.getId());
}

public List<MyObjetc> getAll(){
    Integer id = (Integer)session.getAttribute("myobject");
    return dao.getAll(id);
}

Page normally displays and mounts the table every time you change the ID parameters. EX: if table get 50 register and start browsing the pages, simply add everything.

I solved some of the problem by putting it. c: if in c: set, pagination works normally, problem and now if I change the id parameter that arrives on the page by another, it gets the old list.

<c:if test="#{sessionScope.myobject == null}">
    <c:set var="myobject" value="#{MyBean.MyObject.id}" scope="session"/>
</c:if>

I'm looking for a solution to this problem.

If you remove the c: if pagination does not work correctly, but every time you change the ID the new table comes. If you put the c: if pagination works, but the table does not switch.

I would have to remove the variable myobject from the session or by it to null, I do not know how. I tried to work with ViewScope but the paging does not work correctly. I would like a solution that solved both problems at once.

    
asked by anonymous 16.07.2015 / 06:30

1 answer

1

I solved both problems

I removed the page

<c:if test="#{sessionScope.myobject == null}">
    <c:set var="myobject" value="#{MyBean.MyObject.id}" scope="session"/>
</c:if>

I changed the:

<f:metadata>
    <f:viewParam name="id" value="#{sessionScope.myobject}" />
    <f:event type="preRenderView" listener="#{MyBean.exibir}" />
</f:metadata>

And I changed two display methods and getAll

public void exibir(){
    String id = (String)session.getAttribute("myobject");
    myObject = dao.getMyObjetc(Integer.parseInt(id));
}

public List<MyObjetc> getAll(){
    String id = (String)session.getAttribute("myobject");
    return dao.getAll(Integer.parseInt(id));
}
    
16.07.2015 / 07:35