问题
i'm trying to set the filtering and sorting for a column of my datatable dynamically from a managed bean, but i had a problem regarding the value that i should give to those methods, here is the code i tried :
/*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);
everything is rendered well except the column filter,it won't show a list of options that i provide :
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;
}
回答1:
Your XHTML example is invalid:
<p:column
filterBy="#{exam.examen.studyPatientState}"
sortBy="#{exam.examen.studyPatientState}"
>
The filterBy must represent the sole property name. The same applies to sortBy.
This is valid XHTML:
<p:column
filterBy="studyPatientState"
sortBy="studyPatientState"
>
Just do the same in Java code:
patSate.setFilterBy("studyPatientState");
patSate.setSortBy("studyPatientState");
In the future, try to get the XHTML working and valid first, then translate exactly that XHTML to Java code. There's nothing which can't be done in XHTML but only in Java.
来源:https://stackoverflow.com/questions/20000815/column-setfilterby-and-column-setsortby-what-type-of-parameter-should-i-give