I have pre-made views displayed on my website. The data query is done via Hibernate from a DB2 database and is displayed with JSF. The whole thing runs on a local JBoss server.
This is the logical bean behind the HTML:
@Named(value = "vb")
@ViewScoped
public class ViewBean implements Serializable {
@Inject
private ViewHandler vh;
@PostConstruct
public void init() {
}
public List<PortView> getPVList() {
return vh.getPortViewList();
}
The ViewHandler vh
retrieves the List of the view(s) coming from the respective entity. (see below)
@Stateless
public class ViewHandler {
public List<PortView> getPortViewList() {
List<PortView> pvlist = em.createQuery("SELECT v FROM PortView v", PortView.class).getResultList();
return pvlist;
}
Here you see the p:datatable in my html:
<html>
<h:body>
<h:form>
<p:dataTable var="portview" value="#{vb.PVList}"
resizableColumns="true" stickyHeader="true"
stickyTopAt=".layout-topbar"
style="margin-left:10%; margin-right:10%; font-family: verdana">
<p:column style="width: 0px" sortable="false" />
<p:column headerText="Instance" sortBy="#{portview.instance}"
style="font-family: verdana; text-align:left">
<h:outputText value="#{portview.instance}" />
</p:column>
[more columns]
</p:dataTable>
</h:form>
</h:body>
</html>
Problem: Each single column cannot be sorted, the content is always random. What should I do to solve this?
Fortunately @Melloware was able to answer my question: You simply add
sortBy="#{var.property}"
to thep:dataTable
attribute.For documentation, see here.