'PrimeFaces p:autoComplete over List of Objects, failed Conversion
I'm having some trouble using p:autoComplete properly, I am trying to let a user search based on a text field of an object. Currently I have the following:
<p:autoComplete forceSelection="true" value="#{answer.destinationQuestion}"
completeMethod="#{editorView.completeText}"
var="destinationQuestion" itemLabel="#{destinationQuestion.questionText}"
itemValue="#{destinationQuestion}"/>
public List<Question> completeText(String query) {
List<Question> ret = new ArrayList<Question>();
for(Section section : this.survey.getSections()) {
for(Question question : section.getQuestion()) {
if(question.getQuestionText() != null && question.getQuestionText().contains(query)) {
ret.add(question);
}
}
}
return ret;
}
My expectation with this code is that the autoComplete would let a user select a single Question instance, but once a value is selected from the autoComplete and an update event is triggered, I receive the following exception:
java.lang.IllegalArgumentException: Cannot convert Question@228bb9f7 of type class java.lang.String to class Question
It has been suggested that I use a converter, but I am confused why the value selected is being treated as a String rather than my Question object, since itemValue is defined to be a Question object.
Edit: This is on PrimeFaces 6.2
Solution 1:[1]
Based on your code, what I can tell you is, you are missing a custom converter class.
You should use it like converter="#{questionConverter}".
For further reference you can see this
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Asgar |
