2016-04-18 3 views
1

しかし、私のテーブルのいくつかの列は、フォーマットされた値を持っています(例:0と1をデータベースに表示し、 "いいえ"と "はい"と表示される)ので、filterByはdb値を使用しました。私は私の価値をフォーマットするコンバータを使用します。 編集:TMXキーを使用して、異なる言語で値を表示します。これは私の問題の一部です。ここで私はデータテーブルとダイナミクスの列<code><p:columns/></code>で作業しており、各列にfilterByがあります。

私の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使用TMKキーを返却しなければならないということである私のモデルに

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; 
    } 

}

を次のコードで最初の解説によって与えられた解決策を試してみました/

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

答えて

0

変換された表示値はgetAsStringメソッドはオブジェクトを変更しません。したがって、staffListController.model.staffSearchのリストを作成する際に値を変更する必要があります。あなたはDBから値を取得するときリスト自体を変更します

+0

ありがとうございました。はい、あなたは正しいです。私は、次の例でそのような何か パブリック文字列getStfResourceLaptopFormat(){ \tをしようとした場合(stfResourceLaptop!= null)の \t { \t \t(stfResourceLaptop.equals( "1")) \t \t { \t \t場合\t "common.yes"を返します。 \t \t}他 \t \t IF(stfResourceLaptop.equals( "0")) \t \t { \t \t \t戻る "common.no"。 \t \t} \t \t他の場合はnullを返します。 \t} \t else \t { \t \t return null; \t} \t \t } 問題は、TMXキーを返してからTMXキーを追加する必要があることです –

関連する問題

 関連する問題