The <p:datatable> is not paginated

Asked

Viewed 256 times

1

Get a page that gets a stop.

    <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>

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 parameter. EX: if the table takes 50 record and starts browsing the pages, simply add all.

I solved part of the problem by asking. c:if in c:set, paging works normally, problem and that now if I exchange the id parameter that arrives in the page for 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 take c:if the paging does not work correctly, however every time you change the ID the new table comes. If you put c:if the paging works, but the table does not change.

I’d have to remove the myobject variable from the session or null it, I don’t know how. I tried to work with Viewscope but the paging does not work properly. I would like a solution that solves both problems at the same time.

1 answer

1

I solved both problems

removed from the page

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

changed the:

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

And I changed two methods display 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));
}

Browser other questions tagged

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