You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Dmitriy Neretin <dm...@googlemail.com> on 2013/07/09 19:58:04 UTC

FormComponent independent from the Model/Model object

Hi everyone,

I have a dummy question:

If I have a panel with a form (not everything is my code) ->

public class MyPanel{

  public MyPanel(id, IModel<MyObj> model){
        super(id, new CompoundPropertyModel<MyObj>(model);
        ....
        Form<MyObj> form = new Form("id", model);
        form.add(new AjaxCheckBox("anyStupidId");
        add(form);

     }

}

And I want to add a Component (AjaxCheckBox) to the form above, but this
component shouldn't have anything to do with a model object. It's purpose
is just a change the state of the input fields. If I check the box the
field should be deactivated and vice versa. Nothing more.

My problem is, that Wicket thinks (and I even know  why :)) the
"anyStupidId" is a field of MyObj and tries to change the value... Well,
the checkbox should be inside of the form, but I don't know if is it
possible to make this checkbox independent from the Model handling... How
can I tell wicket, "hey dude, anyStupidId has nothing to do with MyObj, it
is really just a stupid id"

Regards,
Dmitriy

Re: FormComponent independent from the Model/Model object

Posted by Dmitriy Neretin <dm...@googlemail.com>.
Thanks to all! I used the Marios approach... The workaroud with another
Model worked perfectly. :)

@Richard: Everything is possible with javasript, but if wicket offers a
huge feature set, I see no need to use js...

Regards,
Dmitriy

2013/7/10 Paul Bors <pa...@bors.ws>

> You don't want an empty model either, just declare a class field and use a
> PropertyModel instead.
>
> Like so:
>
>  public class MyPanel {
>    // Add the field and its getter/setter (not shown here)
>    private boolean myCheckBoxState;
>
>    public MyPanel(id, IModel<MyObj> model){
>          super(id, new CompoundPropertyModel<MyObj>(model);
>          ....
>          Form<MyObj> form = new Form("id", model);
>          // Specify a different model for your form fields that are
> independent of MyObj
>          form.add(new AjaxCheckBox("anyStupidId", new
> PropertyModel<MyPanel>("myCheckBoxState", MyPanel.this));
>          add(form);
>    }
>
>  }
>
> ~ Thank you,
>   Paul Bors
>
> -----Original Message-----
> From: Joachim Schrod [mailto:jschrod@acm.org]
> Sent: Tuesday, July 09, 2013 6:27 PM
> To: users@wicket.apache.org
> Subject: Re: FormComponent independent from the Model/Model object
>
> Dmitriy Neretin wrote:
> > Hi everyone,
> >
> > I have a dummy question:
> >
> > If I have a panel with a form (not everything is my code) ->
> >
> > public class MyPanel{
> >
> >   public MyPanel(id, IModel<MyObj> model){
> >         super(id, new CompoundPropertyModel<MyObj>(model);
> >         ....
> >         Form<MyObj> form = new Form("id", model);
> >         form.add(new AjaxCheckBox("anyStupidId");
> >         add(form);
> >
> >      }
> >
> > }
> >
> > And I want to add a Component (AjaxCheckBox) to the form above, but
> > this component shouldn't have anything to do with a model object.
>
> Why don't you construct it with an empty model object, i.e., with new
> Model()? Then the CPM from the panel is not accessed.
>
>         Joachim
>
> --
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> Joachim Schrod, Roedermark, Germany
> Email: jschrod@acm.org
>
>
> ---------------------------------------------------------------------
> 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: FormComponent independent from the Model/Model object

Posted by Paul Bors <pa...@bors.ws>.
You don't want an empty model either, just declare a class field and use a PropertyModel instead.

Like so:

 public class MyPanel {
   // Add the field and its getter/setter (not shown here)
   private boolean myCheckBoxState;
   
   public MyPanel(id, IModel<MyObj> model){
         super(id, new CompoundPropertyModel<MyObj>(model);
         ....
         Form<MyObj> form = new Form("id", model);
         // Specify a different model for your form fields that are independent of MyObj
         form.add(new AjaxCheckBox("anyStupidId", new PropertyModel<MyPanel>("myCheckBoxState", MyPanel.this));
         add(form);
   }
 
 }

~ Thank you,
  Paul Bors

-----Original Message-----
From: Joachim Schrod [mailto:jschrod@acm.org] 
Sent: Tuesday, July 09, 2013 6:27 PM
To: users@wicket.apache.org
Subject: Re: FormComponent independent from the Model/Model object

Dmitriy Neretin wrote:
> Hi everyone,
> 
> I have a dummy question:
> 
> If I have a panel with a form (not everything is my code) ->
> 
> public class MyPanel{
> 
>   public MyPanel(id, IModel<MyObj> model){
>         super(id, new CompoundPropertyModel<MyObj>(model);
>         ....
>         Form<MyObj> form = new Form("id", model);
>         form.add(new AjaxCheckBox("anyStupidId");
>         add(form);
> 
>      }
> 
> }
> 
> And I want to add a Component (AjaxCheckBox) to the form above, but 
> this component shouldn't have anything to do with a model object.

Why don't you construct it with an empty model object, i.e., with new Model()? Then the CPM from the panel is not accessed.

	Joachim

--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Joachim Schrod, Roedermark, Germany
Email: jschrod@acm.org


---------------------------------------------------------------------
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: FormComponent independent from the Model/Model object

Posted by Joachim Schrod <js...@acm.org>.
Dmitriy Neretin wrote:
> Hi everyone,
> 
> I have a dummy question:
> 
> If I have a panel with a form (not everything is my code) ->
> 
> public class MyPanel{
> 
>   public MyPanel(id, IModel<MyObj> model){
>         super(id, new CompoundPropertyModel<MyObj>(model);
>         ....
>         Form<MyObj> form = new Form("id", model);
>         form.add(new AjaxCheckBox("anyStupidId");
>         add(form);
> 
>      }
> 
> }
> 
> And I want to add a Component (AjaxCheckBox) to the form above, but this
> component shouldn't have anything to do with a model object.

Why don't you construct it with an empty model object, i.e., with
new Model()? Then the CPM from the panel is not accessed.

	Joachim

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Joachim Schrod, Roedermark, Germany
Email: jschrod@acm.org


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


Re: FormComponent independent from the Model/Model object

Posted by Marios Skounakis <ms...@gmail.com>.
If you want to change the state of the input fields via javascript then do
what Richard said. I guess since you are using an AjaxCheckBox you want to
do it on the server side via ajax. So, here's what you need to do:

add a boolean property to the Panel (e.g. "componentsEnabled") and bind
AjaxCheckBox to it: form.add(new AjaxCheckBox("anyStupidId", new
PropertyModel<Boolean>(this, "componentsEnabled")).

Now whenever the checkbox is updated, the change is reflected to the
componentsEnabled property. You can use this property in the onConfigure
method of the panel or the individual components to alter their state:
e.g. form.add(new TextField("name") {
 public void onConfigure() {
   setEnabled(componentsEnabled);
 }
});

To get the update working after the checkbox is clicked you need to handle
its onUpdate method and add the components whose change should change to
the ajax request target.

Hope this helps,
Marios


On Tue, Jul 9, 2013 at 8:58 PM, Dmitriy Neretin <
dmitriy.neretin@googlemail.com> wrote:

> Hi everyone,
>
> I have a dummy question:
>
> If I have a panel with a form (not everything is my code) ->
>
> public class MyPanel{
>
>   public MyPanel(id, IModel<MyObj> model){
>         super(id, new CompoundPropertyModel<MyObj>(model);
>         ....
>         Form<MyObj> form = new Form("id", model);
>         form.add(new AjaxCheckBox("anyStupidId");
>         add(form);
>
>      }
>
> }
>
> And I want to add a Component (AjaxCheckBox) to the form above, but this
> component shouldn't have anything to do with a model object. It's purpose
> is just a change the state of the input fields. If I check the box the
> field should be deactivated and vice versa. Nothing more.
>
> My problem is, that Wicket thinks (and I even know  why :)) the
> "anyStupidId" is a field of MyObj and tries to change the value... Well,
> the checkbox should be inside of the form, but I don't know if is it
> possible to make this checkbox independent from the Model handling... How
> can I tell wicket, "hey dude, anyStupidId has nothing to do with MyObj, it
> is really just a stupid id"
>
> Regards,
> Dmitriy
>

Re: FormComponent independent from the Model/Model object

Posted by "Richard W. Adams" <RW...@UP.COM>.
Well, one approach is create it as a normal HTML control & not render it 
via Wicket. You can just attach a standard Javascript event (such as 
onclick) to get the behavior you want.

Bottom line: You don't have to "Wicketize" everything on your page. Just 
because you have a hammer, it doesn't mean everything is a nail.




From:   Dmitriy Neretin <dm...@googlemail.com>
To:     users@wicket.apache.org
Date:   07/09/2013 12:58 PM
Subject:        FormComponent independent from the Model/Model object



Hi everyone,

I have a dummy question:

If I have a panel with a form (not everything is my code) ->

public class MyPanel{

  public MyPanel(id, IModel<MyObj> model){
        super(id, new CompoundPropertyModel<MyObj>(model);
        ....
        Form<MyObj> form = new Form("id", model);
        form.add(new AjaxCheckBox("anyStupidId");
        add(form);

     }

}

And I want to add a Component (AjaxCheckBox) to the form above, but this
component shouldn't have anything to do with a model object. It's purpose
is just a change the state of the input fields. If I check the box the
field should be deactivated and vice versa. Nothing more.

My problem is, that Wicket thinks (and I even know  why :)) the
"anyStupidId" is a field of MyObj and tries to change the value... Well,
the checkbox should be inside of the form, but I don't know if is it
possible to make this checkbox independent from the Model handling... How
can I tell wicket, "hey dude, anyStupidId has nothing to do with MyObj, it
is really just a stupid id"

Regards,
Dmitriy



**

This email and any attachments may contain information that is confidential and/or privileged for the sole use of the intended recipient.  Any use, review, disclosure, copying, distribution or reliance by others, and any forwarding of this email or its contents, without the express permission of the sender is strictly prohibited by law.  If you are not the intended recipient, please contact the sender immediately, delete the e-mail and destroy all copies.
**