繁体   English   中英

Primefaces数据表filterBy与显示的velue

[英]Primefaces datatable filterBy with the displayed velue

我正在使用数据表和动力学列<p:columns/> ,我在每列上都有一个filterBy。 但我的表的某些列有一个格式化的值(例如:0和1到db并显示为“No”和“Yes”)所以filterBy使用了db值。 我使用转换器来格式化我的价值。 编辑:我使用TMX键以不同语言显示值。 这是我的问题的一部分。

这是我的HTML

<p:dataTable 
                        id="employeeBeanPageItems" 
                        styleClass="table"
                        value="#{staffListController.model.staffSearch}" 
                        rows="15"
                        sortBy="#{_item.stfFullName}" 
                        var="_item"
                        draggableColumns="true"
                        widgetVar="itemsTable" 
                        selectionMode="single" 
                        rowKey="#{_item.stfId}"
                        resizableColumns="true"
                        scrollable="false"
                        tableStyle="width:auto"
                        emptyMessage="#{msg['error.no-result']}"

                        paginator="true"
                        paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                        rowsPerPageTemplate="10,15,20,50">

                        <p:ajax event="rowSelect" listener="#{staffListController.onRowSelect}" />     
                        <p:ajax event="colReorder" listener="#{staffListController.onColumnReorder}" update=":search:menuColonne"/>             
                        <p:columns  filterMatchMode="contains" headerText="#{msg[column.header]}" value="#{staffListController.columns}" var="column" columnIndexVar="colIndex" sortBy="#{_item[column.property]}" filterBy="#{_item[column.property]}">
                            <h:outputText value="#{_item[column.property]}" converter="StaffListConverter"/>              
                        </p:columns>
                    </p:dataTable>

这是我的转换器

@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
    // TODO Auto-generated method stub
        Label label = new Label(value.toString());

    if (value.equals("1") || value.equals("Y"))
    {
        label.setLabel(getRessourceBundle().getString("common.yes"));
    }
    else if (value.equals("0") || value.equals("N"))
    {
        label.setLabel(getRessourceBundle().getString("common.no"));
    }
    else if (value.equals("EMPLOYEE"))
    {
        label.setLabel(getRessourceBundle().getString("staff.employee"));
    }
    else if (value.equals("COMPDEV"))
    {
        label.setLabel(getRessourceBundle().getString("staff.cd"));
    }
    else if (value.equals("MAN"))
    {
        label.setLabel(getRessourceBundle().getString("MAN"));
    }
    else if (value.equals("WOMAN"))
    {
        label.setLabel(getRessourceBundle().getString("WOMAN"));
    }
    else if (value.equals("UNKNOWN"))
    {
        label.setLabel(getRessourceBundle().getString("UNKNOWN"));
    }

    return label.getLabel();
}

   /**
     * Label is to create an object with a String
    */  
  static public class Label implements Serializable {

        private static final long serialVersionUID = 1L;
        @Getter @Setter private String label;

        /**
         * Public constructor of Label 
         * @param String label
         *
         */
      public Label(String label) {
          this.label = label;

      }

        /**
         * Empty constructor
         *
         */
      public Label() {}

        @Override
        public String toString() {
            return label;
        }
  }

}

也许我应该使用不同的方式来格式化我的数据,但我不知道如何。 目标留下来允许filterBy使用。

add:我尝试了第一个评论给出的解决方案,并在我的模型中使用了以下代码

public String getStfResourceLaptopFormat() {
   if (stfResourceLaptop != null)
   {
       if (stfResourceLaptop.equals("1"))
       {
           return "common.yes";
       }
       else if(stfResourceLaptop.equals("0"))
       {
           return "common.no";
       }
       else return null;
   }
   else
   {
       return null;
   }

}

问题是我必须返回TMK密钥然后filterBy使用密钥:/

<p:columns  filterMatchMode="contains" headerText="#{msg[column.header]}" value="#{staffListController.columns}" var="column" columnIndexVar="colIndex" sortBy="#{_item[column.property]}" filterBy="#{_item[column.property]}">
                            <h:outputText value="#{msg[_item[column.property]]}" />               
                        </p:columns>

转换器只转换显示值getAsString方法不改变对象。 因此,您必须在创建staffListController.model.staffSearch列表时更改值。 从DB中获取值时,会在List中更改自身

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM