Thanks for pointing me in that direction. I haven't quite got it working
yet, but at least it is now showing me the role the user has.
Linda
James Carman wrote:
Well, that seems to be the way you're supposed to do this stuff. I'd
tinker with it, starting with the example code, to see if you can get
it working.
On Tue, Jun 2, 2009 at 7:14 AM, Linda van der Pal
<[email protected]> wrote:
That seems to be even worse than CheckBox, as now it doesn't even show the
roles that are saved in the database anymore. (Which it did do before with
the CheckBox.)
Linda
James Carman wrote:
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
<[email protected]> 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: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
------------------------------------------------------------------------
No virus found in this incoming message.
Checked by AVG - www.avg.com Version: 8.5.339 / Virus Database:
270.12.50/2150 - Release Date: 06/02/09 06:47:00
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
------------------------------------------------------------------------
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.339 / Virus Database: 270.12.50/2150 - Release Date: 06/02/09 06:47:00
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]