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
Wicket-user@lists.sourceforge.net
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
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to