JSF & Webflow - <h:selectManyListbox> converting troubles
In JSF, I have this:
<h:selectManyListbox id="createAccountBasicInfo_select_Types"
styleClass="selectManyCheckbox" value="#{party.roles}" size="6"
converter="persistenceObjectToStringTwoWayConverter">
<f:selectItems value="#{accTypes.selectItems}" />
</h:selectManyListbox>
My Converter:
//[...]
import javax.faces.convert.Converter;
//[...]
public class PersistenceObjectToStringJSFConverter implements Converter {
//[...]
public Object getAsObject(FacesContext context, UIComponent component, String value) {
Long id = Long.valueOf(value);
Object object = null;
try {
object = getPersistenceService(context).loadByEntityId(id); // here I load the appropriate record
} catch (CoreException e) {
e.printStackTrace();
} catch (ElementCreationException e) {
e.printStackTrace();
}
return object; //here I need to return an ArrayList of the loaded Objects instead of a single object
}
}
In HTML, I get this:
<select id="form_party:createAccountBasicInfo_select_Types"
name="form_party:createAccountBasicInfo_select_Types" class="selectManyCheckbox"
multiple="multiple" size="6">
<op开发者_如何转开发tion value="171128">Andere</option>
<option value="171133">Interessent</option>
<option value="171130">Kunde</option>
<option value="171131">Lieferant</option>
<option value="171134">Mitarbeiter</option>
<option value="171132">Mitbewerber</option>
<option value="171129">Partner</option>
</select>
The value of each option is an Id, which I have to load from the database. An ArrayList of the selected entries will then be given to the WebFlow and then saved to the database.
When I press my "save" button, the selected items run through a Converter, where I need to load the items from the database (by value, ex. "171128") and add it to an ArrayList, which will be inserted into "party.roles" (check JSF Code).
My problem: I'm getting the following JSF Exception:
/WEB-INF/page/core/fragments/account/accountBasicInfo.xhtml @152,58 value="#{party.roles}": Property 'roles' not writable on type java.util.List
I think there is a problem with my Converter. What do I have to change?
Thank's for you anwsers!
(I'm using JSF 1.2)
The exception is telling that #{party}
is actually a java.util.List
which in turn indeed doesn't have a setRoles()
method so the #{party.roles}
ain't going to work.
The #{party}
should be a managed bean and it should have a private List<Role> roles
property with a getter. The converter should not return a List<Role>
on the getAsObject()
but it should return Role
.
精彩评论