Have you tried using a Check, rather than a CheckBox?  Take a look at
the "form input" example here (view the source code):

http://www.wicketstuff.org/wicket13/forminput/

On Fri, May 29, 2009 at 5:39 AM, Linda van der Pal
<lvd...@heritageagenturen.nl> wrote:
> I am once again making some error in my thinking. I'm trying to edit a user
> in a form, but for some reason not all the values are passed on upon
> submitting. Can anybody have a look and point me in the right direction?
>
> When I save the data I can see the name and the password, but not the roles.
> I have debugged it and I see that it actually puts the roles in an instance
> of User, but when I get to the code that actually saves it all, the roles
> are empty again. (So they have been put in a different instance, but why and
> how?)
>
> Here's the form:
>           // The form
>           Form<User> form = new Form<User>("userdetailform");
>           add(form);
>
>           // The name-field
>           form.add(new TextField<String>("name").setRequired(true));
>
>           // The roles-field
>           CheckGroup rolesGroup = new CheckGroup("roles");
>           CheckBox ownerRole = new CheckBox("owner");
>                     rolesGroup.add(ownerRole);
>                     form.add(rolesGroup);
>
> And here's the User class (name is a variable in DomainObject):
> public class User extends DomainObject {
>   private String password;
>   private List<Role> roles;
>     public User(final Integer id) {
>       super(id);
>       roles = new ArrayList<Role>();
>   }
>
>   public void setPassword(final String password) {
>       this.password = password;
>   }
>   public String getPassword() {
>       return password;
>   }
>
>   public void setRoles(final List<Role> roles) {
>       this.roles = roles;
>   }
>   public List<Role> getRoles() {
>       return roles;
>   }
>     public void addRole(final Role role) {
>       this.roles.add(role);
>   }
>     private boolean hasRole(final RoleName roleName) {
>       for (Role role: roles) {
>           if (role.getName().equals(roleName)) {
>               return true;
>           }
>       }
>       return false;
>   }
>     public boolean isOwner() {
>       return hasRole(RoleName.OWNER);
>   }
>     private void setRole(final RoleName roleName, final Integer friendId,
> final boolean addRole) {
>       Role role = new Role(roleName, friendId);
>       if (addRole) {
>           addRole(role);
>       } else {
>           this.roles.remove(role);
>       }
>   }
>     public void setOwner(final boolean addRole) {
>       setRole(RoleName.OWNER, null, addRole);
>   }
> }
>
> Regards,
> Linda
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to