2013-11-15 22 views
1

我想從託管bean中動態地設置我的數據表中的一列的過濾和排序,但是我有一個關於應該給這些方法的值的問題,下面是我嘗試的代碼:Column.setFilterBy()和Column.setSortBy()應該給我什麼類型的參數?

除了列過濾
/*this is the XHTML that i try to do in Java code : 
    <p:column style="text-align:center;" 
    width="10" 
    id="etatCol" 
    filterBy="#{exam.examen.studyPatientState}" 
    filterOptions="#{examenListBean.etatExamOptions}" 
    filterMatchMode="exact" 
    headerText="Etat" 
    filterStyle="dispo" 
    sortBy="#{exam.examen.studyPatientState}" 
    rendered="true"> 

    <p:graphicImage value="/images/study_State_icons/#{exam.examen.studyPatientState}.png"/> 
    </p:column> 
    */ 

    //Patstate 
    Column patSate = (Column) application.createComponent(Column.COMPONENT_TYPE); 
    patSate.setHeaderText("Etat"); 
    patSate.setWidth("10"); 
    patSate.setId("etatCol"); 
    patSate.setFilterBy("#{exam.examen.studyPatientState}"); 
    patSate.setFilterOptions(etatExamOptions); 
    patSate.setFilterMatchMode("exact"); 
    patSate.setFilterStyle("dispo"); 
    patSate.setSortBy("#{exam.examen.studyPatientState}"); 
    patSate.setRendered(true); 

    GraphicImage patsategraph = (GraphicImage) application.createComponent(GraphicImage.COMPONENT_TYPE); 
    ValueExpression patsategraphExp = ef.createValueExpression(elc, "/images/study_State_icons/#{exam.examen.studyPatientState}.png", Object.class); 
    patsategraph.setValueExpression("value", patsategraphExp); 
    patSate.getChildren().add(patsategraph); 
    table.getChildren().add(patSate); 

一切都很好渲染,它不會顯示的,我提供的選項列表:

etatExamOptions = createFilterOptions(); 

private SelectItem[] createFilterOptions() { 

    SelectItem[] options = new SelectItem[10]; 

    options[0] = new SelectItem("", "X0"); 
    options[1] = new SelectItem(0, "X1"); 
    options[2] = new SelectItem(1, "X2"); 
    options[3] = new SelectItem(2, "X3"); 
    options[4] = new SelectItem(3, "X4"); 
    options[5] = new SelectItem(4, "X5"); 
    options[6] = new SelectItem(5, "X6"); 
    options[7] = new SelectItem(6, "X7"); 
    options[8] = new SelectItem(7, "X8"); 
    options[9] = new SelectItem(8, "X9"); 

    return options; 
} 

回答

2

你的XHTML例子是無效的:

<p:column 
    filterBy="#{exam.examen.studyPatientState}" 
    sortBy="#{exam.examen.studyPatientState}" 
> 

filterBy必須代表唯一的屬性名稱。這同樣適用於sortBy

這是有效的XHTML:

<p:column 
    filterBy="studyPatientState" 
    sortBy="studyPatientState" 
> 

只是做在Java代碼是相同的:

patSate.setFilterBy("studyPatientState"); 
patSate.setSortBy("studyPatientState"); 

在未來,試圖讓XHTML工作和有效的,然後再翻譯正是XHTML到Java代碼。有沒有這不能在XHTML中完成,但只能在Java中完成。

+0

我得到這個錯誤:無法解析表達式[#{exam.ValueExpression [#{exam.examen.studyPatientState}]]] –

+0

我從來沒有真正使用PrimeFaces排序/過濾,但這表明XHTML變體如所示在你的評論中實際上也根本沒有工作。還是呢? – BalusC

+0

事實上,根據PrimeFaces展示示例,這些示例必須表示唯一的屬性名稱,而不是EL值表達式。我更新了答案。 – BalusC

相關問題