Dynamic p:column with c:forEach. Filter ans sort problem

UI Components for JSF
sebasrock
Posts: 5
Joined: 03 Nov 2011, 16:31

15 Nov 2011, 17:36

monakhv wrote:Hi!
I use dynamic column with c:forEach. I do not test filter function but sortBy work very well.

Here is working example

Code: Select all

<p:dataTable id="#{TableId}" var="supportS" value="#{Values}"
                     rows="#{bundle.Config_Row_NumberDialogs}" paginator="true"
                     selectionMode="multiple" selection="#{Selection}">
            
            <c:forEach var="column" items="#{sessionController.settings.supportDialogTable.columns}">
                <p:column sortBy="#{supportS[column.sortByName]}" >
                    <f:facet name="header">
                        <h:outputText value="#{column.headerName}"/>
                    </f:facet>
                    <h:outputText value="#{supportS[column.name]}"/>
                </p:column>
            </c:forEach>


        </p:dataTable>
Column class

Code: Select all

public class Column implements Serializable{
    private String name;//prop name
    private String headerName;//Column header
    private String sortByName;//Object to make sorting

    public Column(String propName, String headerName, String sortByName) {
        this.name = propName;
        this.headerName = headerName;
        this.sortByName = sortByName;
    }


    public String getHeaderName() {
        return headerName;
    }

    public void setHeaderName(String headerName) {
        this.headerName = headerName;
    }
.....

Code: Select all

public abstract class DataTable<T> {
 private List<Column> columns;//active column

 public List<Column> getColumns() {
        return columns;
    }

    public void setColumns(List<Column> columns) {
        this.columns = columns;
    }
...
}



hi monakhv,


you can put here you Code of supportS[column.name] please, i dont understand very well thi

val3rian
Posts: 8
Joined: 16 Jan 2012, 09:34

25 Jan 2012, 16:12

Hi,

seems that someone from Primefaces have seen this forum and tried to use your solution :)

Code: Select all

String resolveField(ValueExpression expression) {
        Object newValue = expression.getValue(FacesContext.getCurrentInstance().getELContext());
        if(newValue == null || !(newValue instanceof String)) {
            String expressionString = expression.getExpressionString();
            expressionString = expressionString.substring(2, expressionString.length() - 1);      //Remove #{}
            return expressionString.substring(expressionString.indexOf(".") + 1);                //Remove var
        }
        else {
            String val = (String) newValue;
            return val.substring(val.indexOf(".") + 1);
        }
    }
Btw: if you have created your columns from backing bean, you have problem that newValue will be "" and so condition should count with this possibility too.

Code: Select all

if(newValue == null || !(newValue instanceof String || newValue == "")) {
Too bad that I cant extend DataHelper class to just ovveride this method and DataTableRenderer constructor ...

marcodelpercio
Posts: 7
Joined: 08 Dec 2014, 20:54

11 Dec 2014, 15:08

Hi,

I have exactly the same problem and the same situation now tih Primefaces 5.1 however unfortunately the org.primefaces.component.datatable.DataHelper class doesn't exist anymore :-(
how do I fix the problem?

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

11 Dec 2014, 15:19

Then your problem is not the same if it cannot be fixed in the same way... Please create a new topic and provide as much detail as possible

marcodelpercio
Posts: 7
Joined: 08 Dec 2014, 20:54

11 Dec 2014, 15:53

Hi,

The problem IS the same, it cannot be fixed in the same way because the fix of anatolse is from 2011 and since that moment Primefaces has changed a lot but the problem is exactly the same.
I have this datatable:

Code: Select all

<p:dataTable var="outfititem" value="#{shipActionBean.getLazyDataModelFor(outfitType)}"  					     		             widgetVar="#{outfitItemsTableId}"   					     		             rowKey="#{outfititem.id.toString()}"  					     		             lazy="true" rows="#{shipActionBean.displayRows}" paginator="true" >	                         				  	                         				 	                         				    
  <c:forEach var="column" items="#{shipActionBean.getColumnsForType(outfitType)}" varStatus="index">  												   
    <p:column sortBy="#{outfititem[column.property]}" headerText="#{column.header}">												   	  
      <c:if test="#{column.dropdownFilter}">													   	  
        <f:facet name="filter">												                
          <p:selectCheckboxMenu label="Filter" onchange="PF('#{outfitItemsTableId}').filter()">												                    
            <f:selectItems value="#{shipActionBean.getFilterOptionsForColumn(outfitType, column.property)}" />												                
          </p:selectCheckboxMenu>												          
        </f:facet>												      
      </c:if>												      
      <h:outputText value="#{outfititem[column.property]}" />			 												   
    </p:column>												
  </c:forEach>	                         				     	                         				  								
</p:dataTable>
I cannot use <p:columns since some <p:column will have to be sortable and some other will have to be filterable and I cannot simply type the list of the <p:column statically because they come from the database and I do not know in advance which columns the table will hold.
I had numerous issues using <ui:repeat (I had the same number of columns always) and using <c:forEach and <p:column works well the only problem is the value of sortBy="" and filterBy="" which doesn't seem to evaluate correctly. instead of evaluating with the current dynamic property of the current outfititem it just evaluates constantly to the string "property]" I tried setting a variable via <c:set or invoking a method but nothing to do. It constantly evaluates to the string of what I type instead of evaluating.

I'm using Primefaces 5.1 stable, Mojarra 2.2.5 on WlidFly 8

I guess I will have to apply the same fix into org.primefaces.component.DataTable into the method resolveSortField()

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

11 Dec 2014, 16:32

The behaviour is the same but that does not mean the issue/cause is... As you mentioned, the version is different, primefaces has moved on, the solution is not applicable etc...

Please create a NEW topic...

marcodelpercio
Posts: 7
Joined: 08 Dec 2014, 20:54

11 Dec 2014, 16:51

Ok,

For anybody interested the new topic is the following: http://forum.primefaces.org/viewtopic.php?f=3&t=40617

Many thanks

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 6 guests