I use the following constructor code:
public DateDropDownChoice(final String id) {
this(id, null);
}
public DateDropDownChoice(final String id, IModel<Calendar> model)
{
super(id);
//.. set default values to children if model is null
}
But how should be able to resolve the model from the parent during the
constructor call? The child-parent relationship gets established by
calling add(new DateDropDownChoice("prop-name")) which gets executed
_after_ the constructor, right? So at that moment my component does not
even know it has a parent.
Of course I could just pass in a reference to the parent and use that one,
but this would mean my component would have a different interface than
e.g. TextField and therefore just does not seem right to me.
To my understanding the place to set my model would be initModel() which
gets called when a call to getModel() returns null. After doing some more
debugging it seems that many components, like e.g. CheckBox, use
onBeforeRender to retrieve their model implicitly by calling getValue().
So I am thinking about moving the initialising code for my components
children from the constructor to this method and have initModel() get the
ModelValue from the parent. But is this the recommended way? Is there one?
On Sat, 28 May 2011, James Carman wrote:
Please list your constructors of your custom component. I believe the
auto-resolving of models from a parent CPM is done during the
constructor (the one with just the component id).
On Sat, May 28, 2011 at 8:27 AM, andrea del bene
<andrea.on....@libero.it> wrote:
Hi,
Have you called setType(Calendar.class) in your custom form component? Does
its model remain 'null'?
Hi all,
I am pretty new to Wicket (using 1.4.10) and have some hard time to figure
out how the interaction between components and models exactly works. So I
was hopeing that someone here could enlighten me or tell me where I should
look (WARNING: Rather lengthy post).
My particular problem is that I have a custom component that extends
FormComponent<Calendar> to display a date in a certain way. This component
is part of a Panel in which I use a CompoundPropertyModel to render an
object containing a calendar among other things (the object is fully
populated and load from the database by using a LoadableDetachableModel
chained to the CompoundPropertyModel).
For the other object fields I simply use TextFields which get populated
properly and when I use a TextField<calendar> instead of my custom component
the field contains the result of Calendar.toString so I guess the Panel it's
children and the corresponding are set up correctly.
But whenever I use my custom component I don't get a reference to that
Calendar instance. I did try to get some insights by looking into the code
of the TextField class and overriding various methods from super classes but
I just did not get it.
To my understanding something like setModel or setModelObject on my
component should be called so I can override this method and do my custom
stuff in it. But somehow this does not happen. During debugging I saw that
the Panel is set as my components parent and everything seeme to be stuck
together correctly. But somehow I can't get the Calendar instance from my
object to get set as my components model value.
So I figure that I am missing some vital point on this topic and would be
very grateful for any advice, like an how to for extending Components or
something similar.
Thanks for reading this far,
Chris
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org