From viewing the source code that this code makes it looks like itemValue generate the value based on the objects toString() method. So bean.question.categories can’t be an arraylist containing categories….at least it does not work. Do I need to make my own converter in order to have this working?
<h:selectManyMenu value="#{bean.question.categories}" id="questionCategories">
<f:selectItems value="#{categoryValuesManager.categories}" var="category"
itemValue="#{category}" itemLabel="#{category.description}"/>
</h:selectManyMenu>
The question entity also has a bi-directional many-to-many relationship with the category entity and it gives me headace!
Because; when making a new question instance the categoriesproperty of that instance is null, right? So I need to assign a empty ArrayList<Category> to it. Then, do I need to loop over each item in that arraylist and assign an arraylist with the one question instance on the category side too?
I think you have to create your own
Converter. JSF cannot automatically convert a string to yourEntityobject.If you successfully created a
Converterthat can convert aStringinput to the correspondingCategoryobject, your<h:selectManyMenu>will give you aList<Category>. Then I think you can assign it directly to the question’scategoriesproperty. You will still have to loop over yourcategoriesList to bind theQuestionentity to each and every of them.