Thanks Eelco for your time. I hope I get the intent even if I did not looked
at Wicket 2.0.

The first solution with CompoundPropertyModel is clear, I just hesitate to
use the component id as the model accessor string. But my hesitation can be
solved with BoundCompoundPropertyModel.

The second solutions is interesting albeit more code is needed.

The last remark is not clear to me, I have look into Wicket 2.0 sources.

Thanks again, Jan

"Eelco Hillenius" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Take a look at how NewUserWizard of wicket-examples/wizard works. It
uses itself as the model object:

public class NewUserWizard extends Wizard<NewUserWizard>
{
...
private static final List<String> allRoles = Arrays.asList(new
String[] { "admin", "user",
"moderator", "joker", "slacker" });

private boolean assignRoles = false;

private User user;

public NewUserWizard(MarkupContainer parent, String id)
{
super(parent, id);

// create a blank user
user = new User();

setModel(new CompoundPropertyModel<NewUserWizard>(this));
...


Then, later on, that is used like:

  new RequiredTextField(this, "user.firstName");
  new RequiredTextField(this, "user.lastName");
  new TextField(this, "user.department");
  new CheckBox(this, "assignRoles");


The point here is that NewUserWizard is used as the compound model
object, nesting the user and assignRoles properties. Instead of
NewUserWizard, we could have any other class to nest those properties,
and instead of a CompoundPropertyModel, we could have just passed the
model in the constructors of the panels that use them. And instead of
relying on one top level model object, we could have used nested
IModel instances:

public class GimmeAll {
  private User user;
  private boolean assignRoles;
  ...
}

public class UserModel extends LoadableDetachableModel<User> {

  private final IModel<GimmeAll> parentModel;

  public UserModel(IModel<GimmeAll> model) {
    this.parentModel = model;
  }

  protected User load() {
    GimmeAll o = parentModel.getObject();
    return (o != null) ? o.getUser() : null;
  }

  protected void onDetach() {
    parentModel.detach();
  }
}

and finally, in 2.0 you can 'force' using the proper model even if it
is not the concrete object yet:

public class SomePanel extends Panel<User> {
  public SomePanel(MarkupContainer parent, IModel<User> model) {
    super(parent, model);
  }
}


Does that help?

Eelco


On 8/22/06, jan_bar <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I would like to see some sample too. In my opinion, the hierarchical model
> sample should be part of the wicket samples. We can very easy partition
our
> pages into Panels, Borders and whatever, but what about models? They are
not
> so easy to use. I think that a set of possible solutions (model - best
> practices) used by core Wicket developers may be of immense help.
>
> Thank you, Jan
>
> "Andre Matheus" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> Could you please explain better the option 2?
>
> If do you have an example it could be useful.
>
> Thanks.
> ___
> André Matheus
>
> On 8/21/06, Eelco Hillenius <[EMAIL PROTECTED]> wrote:
> > Basically you have the choice between either:
> > 1) using observers/ event listeners for notification much like you
> > would probably do with swing;
> > 2) use a hierarchal model that is shared between components so that
> > any change in that model is automatically cascaded.
> >
> > 1) is probably more work and has the danger that it causes a domino
> > effect letting you end up with a zillion listeners, but the advantage
> > is that you don't need a foreign model and it is more loosely bound.
> >
> > My personal preference is usually 2). Not that this model hierarchy
> > can be on the actual model objects as well as on the IModels
> > themselves.
> >
> > Eelco
> >
>
> -------------------------------------------------------------------------
> > Using Tomcat but need to do more? Need to support web services,
security?
> > Get stuff done quickly with pre-integrated technology to make your job
> easier
> > Download IBM WebSphere Application Server v.1.0.1 based on Apache
Geronimo
> > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> > _______________________________________________
> > Wicket-user mailing list
> > Wicket-user@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/wicket-user
> >
>
>
> --
> __
> André Matheus
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job
> easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>
>
>
>
>
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job
easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>
> _______________________________________________
> Wicket-user mailing list
> Wicket-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>
>
>

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job
easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to