Mhh, this approach is giving me a headache. Sometimes the inner
formcomponent models are not wrapped around the outer formcomponent
compound model returned by the overridden getModel(), but directly
around the parent model instead (which is also a compound one). It's
as if the model is accessed directly from its field instead of via the
overridden property. Can I reliably assume that getModel() is
overridable? Otherwise I should do something in the venue of:
public DateComponent(String id, IModel model) {
super(id, model == null ? model : new
CompoundPropertyModel(model));
}
protected IModel initModel() {
return new CompoundPropertyModel(new
PropertyModel(getParent().getModel(), getId()));
}
TIA.
Cheers,
Carlos
On 4/11/07, Carlos Pita <[EMAIL PROTECTED]> wrote:
> I worked out this easier and cleanse way to wrap the model of the
> outer component:
>
> public DateComponent(String id) {
> this(id, null);
> }
>
> public DateComponent(String id, IModel model) {
> super(id, model);
> }
>
> public IModel getModel() {
> return new CompoundPropertyModel(super.getModel());
> }
>
> protected IModel initModel() {
> return new PropertyModel(getParent().getModel(), getId());
> }
>
> Namely, initModel and getModel work in tandem. If model is initialized
> with null, initModel() will lazy-initialize it as the parent's model
> evaluated in the DateComponent id. In any case (model null initialized
> or not) getModel will wrap the resultant model into a
> CompoundPropertyModel. So inside DateComponent you could create, say,
> a year field simply as new TextField("year").
>
> Cheers,
> Carlos
>
>
>
> On 4/10/07, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
> > looks good without actually running the code :)
> >
> > -igor
> >
> >
> > On 4/9/07, Carlos Pita <[EMAIL PROTECTED] > wrote:
> > >
> > > Well, here is what I've done based on your suggestions. Please review
> > > this and tell me if it can be improved, if you are so kind:
> > >
> > > 1) An inherited model that looks into the passed model. If it's not
> > > null it returns a propertymodel for the component id a la
> > > CompoundPropertyModel. If it's null it returns a propertymodel for the
> > > parent's model with the full path of the component. So inside my panel
> > > I can add form components as add(new TextField("month",
> > > Integer.class)) independently of the model passed (null or a real
> > > date)
> > >
> > > private class MyModel extends Model implements IComponentInheritedModel {
> > > ....
> > > public IWrapModel wrapOnInheritance(Component component) {
> > > final IModel wrappedModel;
> > > if (model == null) {
> > > IModel parentModel =
> > DatePanel.this.getParent().getModel();
> > > String path = DatePanel.this.getParent().getId() + "."
> > > + component.getId();
> > > wrappedModel = new PropertyModel(parentModel, path);
> > > } else {
> > > wrappedModel = new PropertyModel(model,
> > component.getId());
> > > }
> > > return new AbstractWrapModel() {
> > > public IModel getWrappedModel() { return wrappedModel;
> > > }
> > > };
> > > }
> > > }
> > >
> > > 2) To have control on when children are really validated and their
> > > models updated:
> > >
> > > public boolean processChildren() { return false; }
> > >
> > > 3) A DatePanel validator that first validate its fields (so they are
> > > converted too) and finally do global validation (validateDate()). Note
> > > that individual validators can do global validation do, depending on
> > > whether the validation was ajax-triggered or not, so validateDate()
> > > will occur depending on the value of the validateDate flag (true for
> > > ajax-validation, false for individual validators during submit
> > > validation). Notice that validateOnNullValue() must return true or
> > > this validator won't be invoked.
> > >
> > > add(new AbstractValidator() {
> > > protected void onValidate(IValidatable validatable) {
> > > validateDate = false;
> > > yearField.validate();
> > > monthField.validate ();
> > > dayField.validate();
> > > validateDate = true;
> > > if (!(yearField.hasErrorMessage() ||
> > > monthField.hasErrorMessage() || dayField.hasErrorMessage())) {
> > > validateDate();
> > > }
> > > }
> > > public boolean validateOnNullValue() { return true; }
> > > });
> > >
> > > 4) updateModel. Just delegate to fields.
> > >
> > > public void updateModel() {
> > > dayField.updateModel();
> > > monthField.updateModel();
> > > yearField.updateModel();
> > > }
> > >
> > > Thank you in advance.
> > > Best regards,
> > > Carlos
> > >
> > >
> > -------------------------------------------------------------------------
> > > Take Surveys. Earn Cash. Influence the Future of IT
> > > Join SourceForge.net's Techsay panel and you'll get the chance to share
> > your
> > > opinions on IT & business topics through brief surveys-and earn cash
> > >
> > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> > > _______________________________________________
> > > Wicket-user mailing list
> > > [EMAIL PROTECTED]
> > > https://lists.sourceforge.net/lists/listinfo/wicket-user
> > >
> >
> >
> > -------------------------------------------------------------------------
> > Take Surveys. Earn Cash. Influence the Future of IT
> > Join SourceForge.net's Techsay panel and you'll get the chance to share your
> > opinions on IT & business topics through brief surveys-and earn cash
> > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> > _______________________________________________
> > Wicket-user mailing list
> > [EMAIL PROTECTED]
> > https://lists.sourceforge.net/lists/listinfo/wicket-user
> >
> >
>
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/wicket-user