1
votes

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?

1
You can put sortBy right on the Datatable itselt and that is the "default sort" when the table is rendered.Melloware
@Melloware you mean like: <:p:datatable [...] sortBy="vb.PVList" /> ?Arthur Hej
No see the sortBy on the Datatable docs: primefaces.github.io/primefaces/8_0/#/components/… It would be sortBy=#{portview.instance} if you wanted the table sorted by default by the instance column.Melloware
@Melloware Thanks, it works exactly as expected! :)Arthur Hej

1 Answers

1
votes

Fortunately @Melloware was able to answer my question: You simply add sortBy="table.column" to the p:datatable attributes.

For documentation, see here.