This content has been marked as final.
Show 4 replies
-
1. Re: Using <s:selectItems> with a list of entities
pgmjsd Feb 28, 2007 4:21 PM (in response to pgmjsd)Here's the view code:
<h:selectOneMenu id="theSelect" value="#{myBean.selectedUser}"> <s:selectItems value="#{myBean.users}" var="user" noSelectionLabel="Select a user..." label="#{user.name}"/> <ec:convertEntity/> </h:selectOneMenu>
Here's the SLSB:@Name("myBean") @Stateful @Logging public class TestBean implements TestLocal { @PersistenceContext private EntityManager em; private List<User> users; private User selectedUser; public List<User> getUsers() { if (users == null) { Query q = em.createQuery("select t from User t join t.roles r where r = :role"); q.setParameter("role", Role.SPECIAL_ROLE); //noinspection unchecked users = q.getResultList(); } return users; } public User getSelectedUser() { return selectedUser; } public void setSelectedUser(User selectedUser) { this.selectedUser = selectedUser; } @Destroy @Remove public void destroy() { } }
I'm using Seam 1.1.6 and EntityConverter 0.1.
The problem happens when rendering the <h:selectOneMenu> for the first time. I can see with the debugger that the ConverterChain has two converters in it: the NoSelectionConverter and the EntityConverter. The EntityConverter never get's called for the list of Users when rendering. -
2. Re: Using <s:selectItems> with a list of entities
pgmjsd Feb 28, 2007 4:53 PM (in response to pgmjsd)So anyway... the end behavior is that I get:
Invalid selection. Selected item cannot be loaded from persistence context
When the form is submitted because the value in the option is the toString() of the User entity, which the EntityConverter doesn't understand. -
3. Re: Using <s:selectItems> with a list of entities
pgmjsd Feb 28, 2007 6:02 PM (in response to pgmjsd)Okay, this looks like some sort of incompatibility with <s:selectItems> and <ec:entityConverter>. The NoSelectionConverter is effectively overriding the EntityConverter in the ConverterChain.
I was able to work around the problem by using my own bean that generates SelectIems with labels and converts the select item values back into the entity objects (similar to http://wiki.jboss.org/wiki/Wiki.jsp?page=SelectItems).
But... this isn't as nice as the EntityConverter, IMO.
Should I not be using EntityConverter? Is this a known issue? -
4. Re: Using <s:selectItems> with a list of entities
pmuir Mar 2, 2007 10:40 AM (in response to pgmjsd)This is fixed in 1.2.0