listShuttle problem after 2. submit with validation errors
captainvoid Jan 12, 2009 9:55 AMI have a form with a simple text input (required) and a listShuttle.
If I leave the text field blank and submit the form I get the expected "value required" message and the page with the form is displayed again. But when
I submit the form a second time, no matter if I leave the text field bank or not, I get a Component j_id3:j_id7 has invalid value expression example.Role@5e2305e message for the listShuttle.
I cannot figure out what's wrong, I have the equals and hashCode method for the class whose instances are loaded in the listShuttle and I have a converter defined in faces-config.xml.
I debugged the application as far as I could- the converter methods are called and also the hashCode/equals methods but (and this might be the cause) sometimes with instances that do not origin from my converter!
Could you RF guys please have a look at this. It is the same set up as in https://jira.jboss.org/jira/browse/RF-1819 - which should be resolved but may be not?
Thanks for any help!
Environment:
RichFaces 3.2.2 GA
JSF RI 1.2
Seam 1.2
Facelets
xhtml:
<h:form> <div> <h:outputLabel value="Name" for="personNameInput" /> <h:inputText id="personNameInput" value="#{person.name}" required="true" /> </div> <div> <rich:panel id="listShuttlePanel"> <rich:listShuttle sourceValue="#{editAction.availableRoles}" targetValue="#{person.roles}" sourceCaptionLabel="Available roles" targetCaptionLabel="Currently selected roles" converter="roleConverter" var="role"> <rich:column> <h:outputText value="#{role.name}" ></h:outputText> </rich:column> </rich:listShuttle> </rich:panel> </div> <div> <h:panelGroup> <h:commandButton action="#{editAction.save}" value="Save" /> </h:panelGroup> </div> </h:form>
Person.java
@Name("person") public class Person { private String Name; private List<Role> roles; public Person() { roles = new ArrayList<Role>(); } public List<Role> getRoles() { return roles; } public void setRoles(List<Role> roles) { this.roles = roles; } public String getName() { return Name; } public void setName(String name) { Name = name; } }
Role.java
public class Role { private String id; private String name; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public boolean equals(Object other) { System.out.println("===== equals called ======"); if ( (this == other ) ) return true; if ( (other == null ) ) return false; if ( !(other instanceof Role) ) return false; Role castOther = ( Role ) other; return (this.getId().equals(castOther.getId())); } public int hashCode() { System.out.println("===== hashCode called ======"); int result = 17; result += 37 * result + (this.getId() == null ? 0 : this.getId().hashCode()); return result; } }
RoleConverter:
public class RoleConverter implements Converter { public static final String SEPARATOR = "@"; public Object getAsObject(FacesContext context, UIComponent ui, String str) { System.out.println("===== Converter: getAsObject called ======"); int splitIndex = str.indexOf(SEPARATOR); String roleId = str.substring(0, splitIndex); String roleName = str.substring(splitIndex + 1); Role role = new Role(); role.setId(roleId); role.setName(roleName); return role; } public String getAsString(FacesContext context, UIComponent ui, Object obj) { System.out.println("===== Converter: getAsString called ======"); Role role = (Role) obj; return role.getId() + SEPARATOR + role.getName(); } }
EditAction.java
@Name("editAction") @Scope(ScopeType.PAGE) @AutoCreate public class EditAction { @Logger private Log logger; @In(create=true) private Person person; private List<Role> availableRoles; @Create public void init() { logger.debug("++++++ initializing availableRoles list ++++"); availableRoles = new ArrayList<Role>(); Role guestRole = new Role(); guestRole.setId("guest"); guestRole.setName("Guest user"); Role userRole = new Role(); userRole.setId("user"); userRole.setName("Normal user"); Role adminRole = new Role(); adminRole.setId("admin"); adminRole.setName("Administrator"); availableRoles.add(guestRole); availableRoles.add(userRole); availableRoles.add(adminRole); } public List<Role> getAvailableRoles() { logger.debug("++++ getAvailableRoles called ++++"); return availableRoles; } public void setAvailableRoles(List<Role> availableRoles) { logger.debug("++++ setAvailableRoles called ++++"); this.availableRoles = availableRoles; } public String save() { logger.debug("+++ saving person '" + person.getName() + "'"); logger.debug("+++ selected roles: []", person.getRoles()); return "/edit/success.xhtml"; } }