Primefaces "sortBy=" funktioniert nicht
Ich entwickle eine Anwendung mit Primefaces + JSF. Meine Daten Tabelle funktioniert, hat aber ein problem beim Sortieren sortBy=
habe ich versucht sortBy="#{pc.rota}"
aber es funktioniert nicht:
Daten der Tabelle zeigen alle Zeilen, die das problem denke ich ist sortBy=
oder meine backing-bean.
page.xhtml
<h:body>
<h:form id="pcEmulation">
<p:dataTable id="dataTablePCEMulation" var="pc" value="#{pCEmulationBean.allPCEmulation}"
rows="10"
rowsPerPageTemplate="5,30,50,100,200,300"
emptyMessage="Não foi encontrado"
>
<f:facet name="header">
PC Emulation Web
</f:facet>
<p:column headerText="PC - TX OLO's" filterValue="#{pc.filtpcn}" filterMatchMode="contains" filterBy="#{pc.filtpcn}" >
<h:outputText value="#{pc.filtpcn}" />
</p:column>
<p:column headerText="Rota" sortBy="rota" >
<h:outputText value="#{pc.rota}" />
</p:column>
<p:column headerText="Origem">
<h:outputText value="#{pc.origem}" />
</p:column>
<p:column headerText="Antigo">
<h:outputText value="#{pc.epcn}" />
</p:column>
<p:column headerText="Destino">
<h:outputText value="#{pc.destino}" />
</p:column>
<p:column headerText="PC-Novo">
<h:outputText value="#{pc.realpcn}" />
</p:column>
</p:dataTable>
<p:blockUI block="dataTablePCEMulation" trigger="dataTablePCEMulation">
LOADING<br />
<p:graphicImage value="/images/loading.gif"/><br />
<p:graphicImage value="/images/tim-banner2.png" width="100px" height="45px"/>
</p:blockUI>
</h:form>
</h:body>
Backing-bean:
@ManagedBean
//@ViewScoped
@SessionScoped
public class PCEmulationBean {
public List<PCEmulation> allPCEmulation;
public List<PCEmulation> getAllPCEmulation() {
PCEmulationDAO dao = new PCEmulationDAO();
try {
allPCEmulation = dao.getAll();
} catch (ClassNotFoundException | SQLException e) {
System.out.println("Problema no metodo list : " + e);
}
return allPCEmulation;
}
}
Nicht verwandt : JSF Ruft Getter mehrere Male, so sollte es nicht enthalten keine Datenbank-Zugriff. es sollte Aussehen, genau so : public X getY() { return y; } stackoverflow.com/questions/2090033/...
InformationsquelleAutor Giovanni Cornachini | 2014-09-12
Du musst angemeldet sein, um einen Kommentar abzugeben.
Für die Art Arbeit, die Sie brauchen, um wieder die gleiche Liste Objekt jedes mal mit dem get, wo in Ihrem Fall, das Sie wieder eine neue Liste von der dao-jedes mal. So sollten Sie nur Holen Sie sich eine neue Liste, wenn die Liste ist bisher null. Den code in Ihre getter sein sollte als unten.
InformationsquelleAutor Danny Taberham
Soweit ich weiß, sortBy Attribut der Datatable angewendet wird, nur für Primitive Datentypen und String. Wenn rota ist ein Objekt, müssen Sie die create-Methode für die Sortierung selbst durch. Alternative, mit sortBy="#{pc.rota.something}" enthalten Primitive Datentypen oder Strings für die Sortierung.
InformationsquelleAutor wittakarn