You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Martin Dietze <di...@fh-wedel.de> on 2013/07/10 15:00:39 UTC
OnChangeAjaxBehavior on FormComponentPanel: model object is null
I'v stumbled across something that is really puzzling me. In our
project a specific sort of inputs needs to be derived from
FormComponentPanel. One of these simply contains a
DropDownChoice<String> of which the model object is simply
passed through.
In some context I added an OnChangeAjaxBehavior to this
component and found that in its onChange() method the
component's model object is always null. Needless to say that if
I attach the behavior to the inner drop down element,
everything's fine, but this thing still seems wrong to me.
I believe I implemented the form component the right way (see
below). Now I am wondering, is what I do not supposed to work
anyway? Or is there anything else I need to take care of apart
from overriding convertInput() and extending onBeforeRender()?
I've created a quickstart project and appended it to this mail,
but for a quick look consider the way I implemented my selection
component:
| private DropDownChoice<String> choice;
|
| public NestedDropDown( String id, IModel<String> model ) {
| super( id, model );
| this.choice = new DropDownChoice<String>( "choice", model, Arrays.asList("Joe", "Patrick", "Ivan") );
| add(this.choice);
| }
|
| @Override
| protected void convertInput() {
| setModelObject(this.choice.getModelObject());
| }
|
| @Override
| protected void onBeforeRender() {
| this.choice.setModelObject( getModelObject() );
| super.onBeforeRender();
| }
And it is used like this:
| final IModel<String> model = new Model<String>("Nothing selected.");
| final Label label = new Label("label", model);
| label.setOutputMarkupId( true );
|
| final NestedDropDown nestedDropDown1 = new NestedDropDown( "dropDown1", Model.of( "Joe" ) );
| nestedDropDown1.add( new OnChangeAjaxBehavior() {
| private static final long serialVersionUID = 2645176698181954589L;
| @Override
| protected void onUpdate( AjaxRequestTarget target ) {
| model.setObject(nestedDropDown1.getModelObject());
| target.add( label );
| }
| } );
Any hint appreciated!
M'bert
--
----------- / http://herbert.the-little-red-haired-girl.org / -------------
=+=
My family says I'm a psychopath, but the voices in my head disagree
Re: OnChangeAjaxBehavior on FormComponentPanel: model object is null
Posted by Sven Meier <sv...@meiers.net>.
You have to attach an AjaxFormComponentUpdatingBehavior to the actual
FormComponent that is bound to the <input> tag.
Otherwise no value will be sent to the server.
Sven
On 07/10/2013 03:00 PM, Martin Dietze wrote:
> I'v stumbled across something that is really puzzling me. In our
> project a specific sort of inputs needs to be derived from
> FormComponentPanel. One of these simply contains a
> DropDownChoice<String> of which the model object is simply
> passed through.
>
> In some context I added an OnChangeAjaxBehavior to this
> component and found that in its onChange() method the
> component's model object is always null. Needless to say that if
> I attach the behavior to the inner drop down element,
> everything's fine, but this thing still seems wrong to me.
>
> I believe I implemented the form component the right way (see
> below). Now I am wondering, is what I do not supposed to work
> anyway? Or is there anything else I need to take care of apart
> from overriding convertInput() and extending onBeforeRender()?
>
> I've created a quickstart project and appended it to this mail,
> but for a quick look consider the way I implemented my selection
> component:
>
> | private DropDownChoice<String> choice;
> |
> | public NestedDropDown( String id, IModel<String> model ) {
> | super( id, model );
> | this.choice = new DropDownChoice<String>( "choice", model, Arrays.asList("Joe", "Patrick", "Ivan") );
> | add(this.choice);
> | }
> |
> | @Override
> | protected void convertInput() {
> | setModelObject(this.choice.getModelObject());
> | }
> |
> | @Override
> | protected void onBeforeRender() {
> | this.choice.setModelObject( getModelObject() );
> | super.onBeforeRender();
> | }
>
> And it is used like this:
>
> | final IModel<String> model = new Model<String>("Nothing selected.");
> | final Label label = new Label("label", model);
> | label.setOutputMarkupId( true );
> |
> | final NestedDropDown nestedDropDown1 = new NestedDropDown( "dropDown1", Model.of( "Joe" ) );
> | nestedDropDown1.add( new OnChangeAjaxBehavior() {
> | private static final long serialVersionUID = 2645176698181954589L;
> | @Override
> | protected void onUpdate( AjaxRequestTarget target ) {
> | model.setObject(nestedDropDown1.getModelObject());
> | target.add( label );
> | }
> | } );
>
> Any hint appreciated!
>
> M'bert
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org