簡體   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