You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "jam.ntk" <ja...@gmail.com> on 2012/07/18 22:07:58 UTC

How can wicket Page form model be accessed from child panel

Here is the hierarchy

Parent WebPage contains Panel. Webpage has a form

add(this.form = new Form("form", new CompoundPropertyModel<LoginUser>(new
LoginUserModel(user))) {

@Override protected void onSubmit() { .....

Now on webpage form submit, in the Panel I need to get the updated LoginUser
from form updates. I tried to pass LoginUserModel (which is
LoadableDetachableModel) to the panel constructor, the transient object
<LoginUser> is there during Panel initialization, *however on submit when in
the Panel, the transientobject is null in LoginUserModel* why is it null? I
have passed to the Panel constructor like PagePanel(...., final
IModel<LoginUser> smodel).  

Also there are memeber fields which represents propertyfields like : 
private String email; 

this.form.add(dataContainer = new WebMarkupContainer("dataContainer"));
dataContainer.add(new DropDownChoice<Data>("data", Data.selectAll(), new
ChoiceRenderer<Data>("name", "id")).setNullValid(true));

would the updated value of dropdown be also available in Panel as part of
Model being passed to constructor. Please provide directions/examples.
Thanks in advance  

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-can-wicket-Page-form-model-be-accessed-from-child-panel-tp4650608.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How can wicket Page form model be accessed from child panel

Posted by Bertrand Guay-Paquet <be...@step.polymtl.ca>.
Ah now I'm starting to understand. The "Wicket way" as I understand it 
is to validate in the form submit and its components. Your validator 
however will need a reference to the current value of those checkboxes. 
I'm guessing the checkboxes are not part of the form in your case, 
otherwise this is very easy (just access the form component of the 
form). If they are not part of the form, you should share a model 
between each checkbox and the form validator to control the activation 
of the validation.

On 19/07/2012 2:12 PM, jam.ntk wrote:
> I have two fields on the webpage which needs be validated for not being blank
> if user has selected few checkboxes which are part of the panel. So I
> thought of to have a validate method in the panel. Are you suggesting that
> instead of validating in the panel I validate in the form submit of webpage?
>
> Please suggest
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-can-wicket-Page-form-model-be-accessed-from-child-panel-tp4650608p4650632.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How can wicket Page form model be accessed from child panel

Posted by "jam.ntk" <ja...@gmail.com>.
I have two fields on the webpage which needs be validated for not being blank
if user has selected few checkboxes which are part of the panel. So I
thought of to have a validate method in the panel. Are you suggesting that
instead of validating in the panel I validate in the form submit of webpage?

Please suggest 

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-can-wicket-Page-form-model-be-accessed-from-child-panel-tp4650608p4650632.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How can wicket Page form model be accessed from child panel

Posted by Bertrand Guay-Paquet <be...@step.polymtl.ca>.
Why do you have a validate() method in your panel if it isn't part of 
the form?

When you get to the form's onSubmit() method, all the models used in the 
form components have already been updated. This occurs after all the 
validators of the form and its components are executed. Therefore, if 
you use the same model in the form and in the panel, the panel will also 
"see" the new model object set by the form component *but only after all 
form validation occurs*. http://stackoverflow.com/a/4641827/1030527 has 
a good writeup of the form processing flow.

On 19/07/2012 9:31 AM, jam.ntk wrote:
> ok, I need to check the form attribute value in the vaildate() method of
> panel. If thats the case then  i guess i cannot get the updated model in the
> validate method.
>
> So the workaround for me is to use getters of components (TextField,
> DropDownChoice etc) from webpage in the panel validate method. However as
> per you suggested I see blank value for #getConvertedInput() to these
> components. Sorry if these are basic questions, but i am learning wicket.
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-can-wicket-Page-form-model-be-accessed-from-child-panel-tp4650608p4650625.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How can wicket Page form model be accessed from child panel

Posted by "jam.ntk" <ja...@gmail.com>.
ok, I need to check the form attribute value in the vaildate() method of
panel. If thats the case then  i guess i cannot get the updated model in the
validate method. 

So the workaround for me is to use getters of components (TextField,
DropDownChoice etc) from webpage in the panel validate method. However as
per you suggested I see blank value for #getConvertedInput() to these
components. Sorry if these are basic questions, but i am learning wicket. 

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-can-wicket-Page-form-model-be-accessed-from-child-panel-tp4650608p4650625.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How can wicket Page form model be accessed from child panel

Posted by Bertrand Guay-Paquet <be...@step.polymtl.ca>.
On 19/07/2012 3:26 AM, jam.ntk wrote:
> you are right that the LoginUserModel gets null. Now can you please suggest
> how and where should I reload the LoginUserModel?
 From my previous email: "You need to reload it in the 
LoadableDetachableModel.load() method."
> If in the panel, I try to call this.scmodel.getObject() in the validate()
> method I still get the old LoginUser Object. When the control goes back to
> page form submit, the LoginUser newUser = getModelObject(); returns the
> updated object.
In the form processing process, the models are only updated after 
successful validation. You need to use FormComponent#getConvertedInput 
to get the input for validation. See the javadoc for Form for more info.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How can wicket Page form model be accessed from child panel

Posted by "jam.ntk" <ja...@gmail.com>.
you are right that the LoginUserModel gets null. Now can you please suggest
how and where should I reload the LoginUserModel?

If in the panel, I try to call this.scmodel.getObject() in the validate()
method I still get the old LoginUser Object. When the control goes back to
page form submit, the LoginUser newUser = getModelObject(); returns the
updated object.

Please suggest how can I get the updated object in panel? 


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-can-wicket-Page-form-model-be-accessed-from-child-panel-tp4650608p4650618.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How can wicket Page form model be accessed from child panel

Posted by Bertrand Guay-Paquet <be...@step.polymtl.ca>.
Hi,

The transient object in LoginUserModel is null because it was set to 
null in LoadableDetachableModel.detach(). You need to reload it in the 
LoadableDetachableModel.load() method.

For form submit examples, see 
http://www.wicket-library.com/wicket-examples/forminput/

I think the answer is yes to your last question, but I'm not sure I 
understand it.

Bertrand

On 18/07/2012 4:07 PM, jam.ntk wrote:
> Here is the hierarchy
>
> Parent WebPage contains Panel. Webpage has a form
>
> add(this.form = new Form("form", new CompoundPropertyModel<LoginUser>(new
> LoginUserModel(user))) {
>
> @Override protected void onSubmit() { .....
>
> Now on webpage form submit, in the Panel I need to get the updated LoginUser
> from form updates. I tried to pass LoginUserModel (which is
> LoadableDetachableModel) to the panel constructor, the transient object
> <LoginUser>  is there during Panel initialization, *however on submit when in
> the Panel, the transientobject is null in LoginUserModel* why is it null? I
> have passed to the Panel constructor like PagePanel(...., final
> IModel<LoginUser>  smodel).
>
> Also there are memeber fields which represents propertyfields like :
> private String email;
>
> this.form.add(dataContainer = new WebMarkupContainer("dataContainer"));
> dataContainer.add(new DropDownChoice<Data>("data", Data.selectAll(), new
> ChoiceRenderer<Data>("name", "id")).setNullValid(true));
>
> would the updated value of dropdown be also available in Panel as part of
> Model being passed to constructor. Please provide directions/examples.
> Thanks in advance
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-can-wicket-Page-form-model-be-accessed-from-child-panel-tp4650608.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org