Re: CheckGroup, CheckBox and Check

2008-03-14 Thread Igor Vaynberg
checkgroup's model is the selection mode, so it should be bound to
user's assigned roles list, not the list of all available roles.

-igor

On Fri, Mar 14, 2008 at 7:45 AM, Greg Dunn [EMAIL PROTECTED] wrote:

  I've got a collection of beans (roles) containing user authorization
  roles that I'm using as the Model for a ListView.  I'm confused by the
  interaction between CheckGroups, Check's and CheckBox's.  If I use
  CheckBox my roles show up selected if the user has the role, but I can't
  get the Model Object when I submit.  If I use Check the roles the user
  has do not show up selected, but I get the Model Object after I submit.

  My code for creating the CheckGroup ListView:

 rolesGroup = new CheckGroup(rolesGroup, roles);
 add(rolesGroup);
 ListView rolesList = new ListView(roleList, roles) {
 protected void populateItem(ListItem item) {
 item.add(new CheckBox(roleCheck,  new
  PropertyModel(item.getModel(), hasRole)));
 item.add(new Label(gwGrpDesc, new
  PropertyModel(item.getModel(), Description)));
 item.add(new Label(gwGrpId, new
  PropertyModel(item.getModel(), GroupId)));
 }}.setReuseItems(true);
 rolesGroup.add(rolesList);
 rolesGroup.add(new
  CheckGroupSelector(rolesGroupSelector));


  And getting the model object in onSubmit():

 List userRoles = (List) rolesGroup.getModelObject();

  -
  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]



RE: CheckGroup, CheckBox and Check

2008-03-14 Thread Greg Dunn
Sorry if I'm being dense.  I'm coming to Wicket from the Struts world.
;)

The roles beans in the collection have a Boolean property 'hasRole'
which I use to set the checkbox state.  It has other properties I use to
display the descriptions.

Maybe it will be helpful for me to explain why the rolesGroup object
gets passed on when I use Check but not when I use CheckBox.

That said, I don't really need to use a CheckGroup, I did that because
the list of roles isn't fixed, I need to get the latest set from the
database. Would it be easier to just use a series of checkboxes and (if
it's not too much trouble) how could I go about that?

Thanks

Greg


-Original Message-
From: Igor Vaynberg [mailto:[EMAIL PROTECTED] 
Sent: Friday, March 14, 2008 10:59 AM
To: users@wicket.apache.org
Subject: Re: CheckGroup, CheckBox and Check

checkgroup's model is the selection mode, so it should be bound to
user's assigned roles list, not the list of all available roles.

-igor

On Fri, Mar 14, 2008 at 7:45 AM, Greg Dunn [EMAIL PROTECTED] wrote:

  I've got a collection of beans (roles) containing user
authorization
  roles that I'm using as the Model for a ListView.  I'm confused by
the
  interaction between CheckGroups, Check's and CheckBox's.  If I use
  CheckBox my roles show up selected if the user has the role, but I
can't
  get the Model Object when I submit.  If I use Check the roles the
user
  has do not show up selected, but I get the Model Object after I
submit.

  My code for creating the CheckGroup ListView:

 rolesGroup = new CheckGroup(rolesGroup, roles);
 add(rolesGroup);
 ListView rolesList = new ListView(roleList, roles) {
 protected void populateItem(ListItem item) {
 item.add(new CheckBox(roleCheck,  new
  PropertyModel(item.getModel(), hasRole)));
 item.add(new Label(description, new
  PropertyModel(item.getModel(), description)));
 item.add(new Label(groupId, new
  PropertyModel(item.getModel(), groupId)));
 }}.setReuseItems(true);
 rolesGroup.add(rolesList);
 rolesGroup.add(new
  CheckGroupSelector(rolesGroupSelector));


  And getting the model object in onSubmit():

 List userRoles = (List) rolesGroup.getModelObject();

  -
  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]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: CheckGroup, CheckBox and Check

2008-03-14 Thread Igor Vaynberg
CheckGroup and Check work like this:

CheckGroupT(String id, IModelCollectionT selected);
CheckT(String id, IModelT)

so checkgroup has the model that holds your selection of objects of
type T, while each Check component's model contains an item of type T.
when you submit the form checkgroup's selection is cleared and
populated with instances of T from all selected Check components.

CheckBox is different. CheckBox has a model of type Boolean. if
model.getobject() returns true checkbox renders checked, if false
checkbox renders unchecked. Same for when the form is submitted: if
checked checkbox calls model.setobject(true), if not
model.setobject(false)

all of this should be explained in the javadoc...

so assuming you have
class Role{}
class User { SetRole getRoles(); } and you want to use CheckBox, its
model would look like this

class checkboxmodel implements imodel {
  private final IModelRole role;
  private final IModelCollectionRole selection;

   // constructor that takes role and selection

  object getObject() {
 return 
((CollectionRole)selection.getObject()).contains(role.getObject());
   }

   void setObject(Object object) {
 boolean selected=(Boolean)object;
 if (selected) {
((CollectionRole)selection.getObject()).add(role.getObject()); }
 else { ((CollectionRole)selection.getObject()).remove(role.getObject());
}
   }

   void detach() {
  selection.detach();
  role.detach();
}
}


and used like this - assuming listview iterates over all possible roles

final IModel user=...
listview.populateItem(Item item) {
IModel role=item.getModel();
item.add(new CheckBox(role, new CheckBoxModel(user, role));
}

hope this helps get you started

-igor



On Fri, Mar 14, 2008 at 1:27 PM, Greg Dunn [EMAIL PROTECTED] wrote:
 Sorry if I'm being dense.  I'm coming to Wicket from the Struts world.
  ;)

  The roles beans in the collection have a Boolean property 'hasRole'
  which I use to set the checkbox state.  It has other properties I use to
  display the descriptions.

  Maybe it will be helpful for me to explain why the rolesGroup object
  gets passed on when I use Check but not when I use CheckBox.

  That said, I don't really need to use a CheckGroup, I did that because
  the list of roles isn't fixed, I need to get the latest set from the
  database. Would it be easier to just use a series of checkboxes and (if
  it's not too much trouble) how could I go about that?

  Thanks

  Greg




  -Original Message-
  From: Igor Vaynberg [mailto:[EMAIL PROTECTED]
  Sent: Friday, March 14, 2008 10:59 AM
  To: users@wicket.apache.org
  Subject: Re: CheckGroup, CheckBox and Check

  checkgroup's model is the selection mode, so it should be bound to
  user's assigned roles list, not the list of all available roles.

  -igor

  On Fri, Mar 14, 2008 at 7:45 AM, Greg Dunn [EMAIL PROTECTED] wrote:
  
I've got a collection of beans (roles) containing user
  authorization
roles that I'm using as the Model for a ListView.  I'm confused by
  the
interaction between CheckGroups, Check's and CheckBox's.  If I use
CheckBox my roles show up selected if the user has the role, but I
  can't
get the Model Object when I submit.  If I use Check the roles the
  user
has do not show up selected, but I get the Model Object after I
  submit.
  
My code for creating the CheckGroup ListView:
  
   rolesGroup = new CheckGroup(rolesGroup, roles);
   add(rolesGroup);
   ListView rolesList = new ListView(roleList, roles) {
   protected void populateItem(ListItem item) {
   item.add(new CheckBox(roleCheck,  new
PropertyModel(item.getModel(), hasRole)));
   item.add(new Label(description, new
PropertyModel(item.getModel(), description)));
   item.add(new Label(groupId, new


   PropertyModel(item.getModel(), groupId)));
   }}.setReuseItems(true);
   rolesGroup.add(rolesList);
   rolesGroup.add(new
CheckGroupSelector(rolesGroupSelector));
  
  
And getting the model object in onSubmit():
  
   List userRoles = (List) rolesGroup.getModelObject();
  
-
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]


  -
  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]