Original sortBy for PrimeFaces not working

I have a DataTable PrimeFaces 3.2 using apache myfaces 2.0.2. I need an initial look. My JSF looks like this:

<p:dataTable id="serverdata" var="serverdata" sortBy="#{serverdata[0]}" sortOrder="descending" value="#{ serverDataTable.list }" rows="10" editable="true" paginator="true" rowsPerPageTemplate="10,20,50" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"> <f:facet name="header"> Datatable </f:facet> <p:column> <f:facet name="header"> <h:outputText value="Datum"/> </f:facet> <h:outputText value="#{serverdata[0]}"> </h:outputText> </p:column> 

But I get UnsupportedOperationException: The result list is read-only. When I remove the sortBy tag, it works fine.

So my question is: How can I implement the original look?

+4
source share
1 answer

Sorting is performed on the original List . If it is read-only, an exception is thrown. Try the same thing, but with a regular, mutable List

EDIT: create a regular list in a bean:

 public class MyBean { ... List<MyObject> myList = new ArryList<MyObject>(); myList.add(new MyObject("a")); myList.add(new MyObject("b")); myList.add(new MyObject("c")); ... 

then use sorting as follows: value="#{myBean.myList}" var="myVar" sortBy="#{myVar.stringProp}"

EDIT2: If the sort options are strings or numbers, you do not need to configure anything. If you are sorting anything else, you will need to define a custom sortFunction function,

If you use advanced options such as lazy loading (which was broken into bfw in pf 3.2 - you can now upgrade to 3.3), it was released 29.5 and allegedly solved it), you will have to define the user model, taking care about filtering and sorting.

So, if you want to sort your data by the contents of the array, you will need to define the attribute sortFunction="#{myBean.sortData()}"

+4
source

Source: https://habr.com/ru/post/1415551/


All Articles