I have a bean:
public ProjectServiceImpl {
public List<Project> getAllProjects () { ... }
}
I want to list all these projects as items in <h:selectManyListbox>. When user selects one or more items and press submit button, selected items should be converted into projects.
I’m confused a little about how to list items and how correspondent converter should look like?
You need to implement
Converter#getAsString()so that the desired Java Object is been represented in an unique string representation which can be used as HTTP request parameter. Using the database technical ID (the primary key) is very useful here.Then you need to implement
Converter#getAsObject()so that the HTTP request parameter (which is per definitionString) can be converted back to the desired Java Object (Projectin your case)`.Finally just associate this converter with the object type in question, JSF will then take care about conversion when
Projectcomes into the picture no need to specify aconverterIdor af:converter:This way you can just create
SelectItemwithProjectas value.You can get some background info and more ideas out of this blog article: http://balusc.blogspot.com/2007/09/objects-in-hselectonemenu.html