I have a page where the user must input grading for a number of categories. The categories are retrieved dynamically from a database (there are different user types, and for each type you get different categories). As there are subcategories, I have implemented it using <p:treeTable>. I have the grades stored in a map, with the category id as the key and the grade as the value:
HashMap<Integer, Double> detailedGrades
The problem is how to get and set the grade for each category using <p:inputText>, because the category id has to be a parameter in that. I have managed to do the getter like this:
<p:inputText id="cat" value="#registerCandidateGradeBean.getGradeForCat(gradingCat.pkCertGradeCategoryId)}"/>
and in the bean:
public Double getGradeForCat(int catID){
return detailedGrades.containsKey(catID) ? detailedGrades.get(catID) : null;
}
This displays the value in the input field OK, but I don't know how to set the value when the user changes it. I tried with <p:ajax listener> as mentioned here, where I set
<p:ajax listener="#{registerCandidateGradeBean.setGradeForCat1(gradingCat.pkCertGradeCategoryId)}"/>
and in the bean:
public void setGradeForCat1(int catID){
System.out.println(catID);
}
but whenever I change the input value I get a "javax.el.PropertyNotWritableException: Illegal Syntax for Set Operation" exception. I tried to use a valueChangeListener on the inputText
<p:inputText id="cat" value="#registerCandidateGradeBean.getGradeForCat(gradingCat.pkCertGradeCategoryId)}"
valueChangeListener="#{registerCandidateGradeBean.setGradeForCat}"/>
and in the bean:
public void setGradeForCat(ValueChangeEvent e){
System.out.println("called");
//System.out.println(catID);
System.out.println(e.getNewValue());
}
but it never gets called. (I have tried both setGradeForCat(ValueChangeEvent e) and setGradeForCat(ValueChangeEvent e, int catID)). Any ideas?
Forgot to mention: we are using primefaces 5.3.