Eelco Hillenius wrote:
a method like add is deliberately protected by final to ensure it will
work like it is supposed to, no matter what component hierarchy you're
in. So, before opening up such a method, we would like to be
absolutely sure there are no alternatives for it.

In your case there are a couple of things to note:
* It seems that the component that wants to set the model 'owns' the
children. Why not let that component create those children in the
first place (either directly or via a factory method).

because i want a generic component, that can be used for other such cases.

* If that's not what you are looking for - such a structure might be
too static for your taste - I would consider something more explicit.
Why not have something like:

addDateField(TextField field) {
 field.setModel(...)
 add(field);
}

addTimeField(TextField field) {
 field.setModel(...)
 add(field);
}

That's explicit, and it saves you to do ugly instanceof or checks on
type or whatever you had in mind to differentiate between the date and
time fields in the add method if you could override that.

* For doing fancy stuff, consider overriding onAttach (preferably) or
beforeRender. You can visit child components and change models there
too if you like. Wouldn't be my favorite method for elegance though.

i thought of updateModel for getting all values and setting the combined one in the original model.
for replacing the original model, i thought of using onModelChanged. i'll 
create an ICompoundModel, then, components (which are created without a model) 
will use it (initModel() method)


* We might consider adding event methods, like onAdd(Component) and
onReplace(Component) that are called right after a component is added/
replaced. A special not on this is that the add method will dissapear
anyway the next major release as we have the constructor change then.
Replace will still exist. I'd be +1 for this change, but it depends on
what the other developers think of this.

+1 from me, for what it's worth.


Hope this helps,

thanks


Eelco


On 5/8/06, Ittay Dror <[EMAIL PROTECTED]> wrote:
that is not my problem.

my problem is that i have two components (text fields) - one for date, one for time, whose combined value is my model value.

i can, of course, create a custom model, and onSubmit get its values, combine them, and put in the form's model. but this is awkward, and not component oriented.

i want to create a component that means "the values of the children of this component will be combined to its value"

ittay

Martijn Dashorst wrote:
> Ittay,
>
> It seems like you need to create a Panel instead So a much cleaner
> design, and more reusable component would be:
>
> public class MyDatePicker extends Panel {
>     public MyDatePicker(String id, IModel model) {
>         super(id);
>         add(new DatePicker("datepicker", model));
>         add(new TextField("textfield", model));
>     }
> }
>
> <html>
> <body>
> <wicket:panel>
>     <input wicket:id="textfield" type="text" /><span
> wicket:id="datepicker" />
> </wicket:panel>
> </body>
> </html>
>
> Add it to any form, and it will work:
>
> form.add(new MyDatePicker("date", new PropertyModel(person, "birthdate")));
>
> Overriding add is not the right thing to do. Add is usually called in
> constructors, and it is generally considered a bad thing to call
> overridable methods in a constructor as the type hierarchy is not
> completely initialized.
>
> We made quite a lot of method final in our API, see for the reason the
> following faq:
>
>     http://wicketframework.org/faqs.html#why-final
>
> We are also refactoring our component creation/hierarchy composition
> strategy in the next version of Wicket. The add method will be removed
> as a consquence. So depending on overriding add is not the way to go.
>
> Martijn
>
>
> On 5/8/06, *Ittay Dror* <[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>> wrote:
>
>     i want to set the model of the child. i thought of doing that by:
>             child.setModel(myModel);
>             super.add(child);
>
>     what is wrong with that? how else can i do it?
>
>     here's the long story of what i'm trying to acheive:
>     i have a web page with two text fields, for date and time (for the
>     date, i'm already using DatePicker). (they are used to schedule an
>     action)
>     my model has a Date field (CompoundPropertyModel), which i want to
>     be set with the date and time (together)
>
> so, i thought it would be nice to create a CompositeComponent, which
>     will use a MapModel (IModel implementation mapping id to value) in
>     the children. it will have its own model, set by the client, and
>     hooks/strategy to separate its model value to that of the child
>     components, and to restore it when the form is submitted.
>
>     so, the first thing is to set the MapModel in the child components
>
>     ittay
>
>
>     Juergen Donnerstag wrote:
> > You want to do what? add() is used to add Wicket Components to the
>      > component hierarchy. It is NOT used to set or add a model. Child
>      > components can be access by get(childId).
>      >
>      > Juergen
>      >
>      > On 5/8/06, Ittay Dror < [EMAIL PROTECTED]
>     <mailto:[EMAIL PROTECTED]>> wrote:
>      >> I want to create a MarkupContainer component which sets the
>     model of
> >> contained components. but MarkupContainer.add is final, so i can't
>      >> override it. why? what else can i do?
>      >>
>      >> Thanx,
>      >> Ittay
>      >>
>      >> --
>      >> ===================================
>      >> Ittay Dror
>      >> Chief architect, openQRM TL,
>      >> R&D, Qlusters Inc.
>      >> [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
>      >> +972-3-6081994 Fax: +972-3-6081841
>      >>
>      >> http://www.openQRM.org
>      >> - Keeps your Data-Center Up and Running
>      >>
>      >>
>      >> -------------------------------------------------------
>      >> 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 > <http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642>
>      >> _______________________________________________
>      >> Wicket-user mailing list
>      >> Wicket-user@lists.sourceforge.net
>     <mailto: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=k&kid0709&bid&3057&dat1642
> <http://sel.as-us.falkag.net/sel?cmd=k&kid%120709&bid&3057&dat%121642>
>      > _______________________________________________
>      > Wicket-user mailing list
>      > Wicket-user@lists.sourceforge.net
>     <mailto:Wicket-user@lists.sourceforge.net>
>      > https://lists.sourceforge.net/lists/listinfo/wicket-user
>     <https://lists.sourceforge.net/lists/listinfo/wicket-user>
>      >
>
>
>     --
>     ===================================
>     Ittay Dror
>     Chief architect, openQRM TL,
>     R&D, Qlusters Inc.
>     [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
>     +972-3-6081994 Fax: +972-3-6081841
>
>     http://www.openQRM.org <http://www.openQRM.org>
>     - Keeps your Data-Center Up and Running
>
>
>     -------------------------------------------------------
>     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 > <http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642>
>     _______________________________________________
>     Wicket-user mailing list
>     Wicket-user@lists.sourceforge.net
>     <mailto:Wicket-user@lists.sourceforge.net>
>     https://lists.sourceforge.net/lists/listinfo/wicket-user
>
>
>
>
> --
> Wicket 1.2 is coming! Write Ajax applications without touching JavaScript!
> -- http://wicketframework.org


--
===================================
Ittay Dror
Chief architect, openQRM TL,
R&D, Qlusters Inc.
[EMAIL PROTECTED]
+972-3-6081994 Fax: +972-3-6081841

http://www.openQRM.org
- Keeps your Data-Center Up and Running


-------------------------------------------------------
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=k&kid0709&bid&3057&dat1642
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user



--
===================================
Ittay Dror Chief architect, openQRM TL, R&D, Qlusters Inc.
[EMAIL PROTECTED]
+972-3-6081994 Fax: +972-3-6081841

http://www.openQRM.org
- Keeps your Data-Center Up and Running


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