Disabling Individual Checkboxes in CheckGroup

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Disabling Individual Checkboxes in CheckGroup

eugenebalt
How would you disable individual checkboxes in a CheckGroup?

With a CheckBoxMultipleChoice, it's easy: just override isDisabled(int index) for the particular index you want to disable.

But we are using a CheckGroup, not CheckBoxMultipleChoice, because we need a grid layout for our set of checkboxes. The CheckGroup components works via a repeater, such as ListView. We've tried addOrReplace a new ListView, with some new disabled checkboxes, and it doesn't pick it up until it goes to render, which doesn't work for us in an Ajax request.

The new disabled checkboxes in the CheckGroup have to be set as part of the Ajax update. Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Disabling Individual Checkboxes in CheckGroup

Bertrand Guay-Paquet
Hi,

I'm not sure this is what you want, but you can subclass the "Check"
class and override its onComponentTag method to add disabled="disabled"
to the <input> tags you want to disable. You can also do it with a
behavior instead of subclassing.

Remember that if you replace the checkbox html <input>s via ajax to
toggle the disable state of checkboxes, you will likely lose their
current client-side "checked" state. Maybe toggling the "disabled"
attribute via javascript using the component ids would be better.

On 22/04/2013 12:06 PM, eugenebalt wrote:

> How would you disable individual checkboxes in a CheckGroup?
>
> With a CheckBoxMultipleChoice, it's easy: just override isDisabled(int
> index) for the particular index you want to disable.
>
> But we are using a CheckGroup, not CheckBoxMultipleChoice, because we need a
> grid layout for our set of checkboxes. The CheckGroup components works via a
> repeater, such as ListView. We've tried addOrReplace a new ListView, with
> some new disabled checkboxes, and it doesn't pick it up until it goes to
> render, which doesn't work for us in an Ajax request.
>
> The new disabled checkboxes in the CheckGroup have to be set as part of the
> Ajax update. Thanks.
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Disabling-Individual-Checkboxes-in-CheckGroup-tp4658165.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Disabling Individual Checkboxes in CheckGroup

Igor Vaynberg-2
check.setEnabled(false)

-igor

On Mon, Apr 22, 2013 at 2:09 PM, Bertrand Guay-Paquet
<[hidden email]> wrote:

> Hi,
>
> I'm not sure this is what you want, but you can subclass the "Check" class
> and override its onComponentTag method to add disabled="disabled" to the
> <input> tags you want to disable. You can also do it with a behavior instead
> of subclassing.
>
> Remember that if you replace the checkbox html <input>s via ajax to toggle
> the disable state of checkboxes, you will likely lose their current
> client-side "checked" state. Maybe toggling the "disabled" attribute via
> javascript using the component ids would be better.
>
>
> On 22/04/2013 12:06 PM, eugenebalt wrote:
>>
>> How would you disable individual checkboxes in a CheckGroup?
>>
>> With a CheckBoxMultipleChoice, it's easy: just override isDisabled(int
>> index) for the particular index you want to disable.
>>
>> But we are using a CheckGroup, not CheckBoxMultipleChoice, because we need
>> a
>> grid layout for our set of checkboxes. The CheckGroup components works via
>> a
>> repeater, such as ListView. We've tried addOrReplace a new ListView, with
>> some new disabled checkboxes, and it doesn't pick it up until it goes to
>> render, which doesn't work for us in an Ajax request.
>>
>> The new disabled checkboxes in the CheckGroup have to be set as part of
>> the
>> Ajax update. Thanks.
>>
>>
>>
>> --
>> View this message in context:
>> http://apache-wicket.1842946.n4.nabble.com/Disabling-Individual-Checkboxes-in-CheckGroup-tp4658165.html
>> Sent from the Users forum mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Disabling Individual Checkboxes in CheckGroup

eugenebalt
Igor,

The problem is, you do check.setEnabled(false) in ListView.populateItem() for a CheckGroup control.

This method executes AFTER the Ajax update. It's too late to do check.setEnable(false) on the render of the CheckGroup's ListView. We need to disable/enable checkboxes in a CheckGroup as part of the Ajax update.

(This does work with CheckBoxMultipleChoice, because there is no ListView rendering and the checkboxes can be handled individually, but we need a grid layout and we don't get it with that control.)

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Disabling Individual Checkboxes in CheckGroup

Paul Bors
You can always override the getter method when you construct the Checks and
toggle the boolean value via Ajax.

~ Thank you,
   Paul Bors


On Fri, Apr 26, 2013 at 11:39 AM, eugenebalt <[hidden email]> wrote:

> Igor,
>
> The problem is, you do check.setEnabled(false) in *ListView.populateItem()*
> for a CheckGroup control.
>
> This method executes AFTER the Ajax update. It's too late to do
> check.setEnable(false) on the render of the CheckGroup's ListView. We need
> to disable/enable checkboxes in a CheckGroup as part of the Ajax update.
>
> (This does work with CheckBoxMultipleChoice, because there is no ListView
> rendering and the checkboxes can be handled individually, but we need a
> grid
> layout and we don't get it with that control.)
>
> Thanks
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Disabling-Individual-Checkboxes-in-CheckGroup-tp4658165p4658320.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
~ Thank you,
    Paul@Bors.ws
Reply | Threaded
Open this post in threaded view
|

Re: Disabling Individual Checkboxes in CheckGroup

Igor Vaynberg-2
In reply to this post by eugenebalt
On Fri, Apr 26, 2013 at 8:39 AM, eugenebalt <[hidden email]> wrote:
> Igor,
>
> The problem is, you do check.setEnabled(false) in *ListView.populateItem()*
> for a CheckGroup control.

so?

> This method executes AFTER the Ajax update. It's too late to do
> check.setEnable(false) on the render of the CheckGroup's ListView. We need
> to disable/enable checkboxes in a CheckGroup as part of the Ajax update.

you call setenabled(false) on a check. then rerender it using ajax.
perhaps you should show some code so we can better understand what you
are trying to do.

-igor

>
> (This does work with CheckBoxMultipleChoice, because there is no ListView
> rendering and the checkboxes can be handled individually, but we need a grid
> layout and we don't get it with that control.)
>
> Thanks
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Disabling-Individual-Checkboxes-in-CheckGroup-tp4658165p4658320.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Disabling Individual Checkboxes in CheckGroup

eugenebalt
In reply to this post by Paul Bors
Paul: The Check is constructed inside populateItem(). This is already too late, my output shows this happens after the Ajax ecent.

There is no way to construct a Check outside the populateItem, as far as I know. This is how Checks are used:

CheckGroup cg = new CheckGroup("apps");
add(cg);
ListView appListView = new ListView("appList", appList) {
  @Override
  protected void populateItem (ListItem arg0)
  {
     Check app = new Check("app", arg0.getModel(), appsCheckGroup);
     arg0.add(app);
     
     // enabled/disabled here, or in Check constructor
  }
};
appListView.setReuseItems(true);
cg.add(appListView);
Reply | Threaded
Open this post in threaded view
|

Re: Disabling Individual Checkboxes in CheckGroup

eugenebalt
In reply to this post by Igor Vaynberg-2
Here is the full code. This is an urgent problem so any advice much appreciated.

ISSUE: Cannot enable/disable Checks in an Ajax update, their state remains the same.

The Checks in the CheckGroup are supposed to change depending on a DropDown change.

1) On Page Construction, all Checks in the CheckGroup are initially enabled

final CheckGroup appsCheckGroup=new CheckGroup("apps");
appsCheckGroup.setOutputMarkupId(true);
add(appsCheckGroup);
ListView appListView = new ListView("appList", appList) {
        @Override
        protected void populateItem(ListItem arg0) {

                Check app = new Check("app", arg0.getModel(), appsCheckGroup);
                ApplL appObject = (ApplL)arg0.getModelObject();
                app.add(new SimpleAttributeModifier("title",appObject.getApplDc()));
                arg0.add(app);

                         app.setEnabled(true);

        Label lblApp = new Label("lblApp", appObject.getApplCd());
        lblApp.add(new SimpleAttributeModifier("title", appObject.getApplDc()));
        arg0.add(lblApp);
        }
};
appListView.setReuseItems(true);
appsCheckGroup.add(appListView);


2) In the Ajax Request (invoked from a separate DropDown):

structureDropDown.add(new AjaxFormComponentUpdatingBehavior("onchange")
{
                final CheckGroup appsCheckGroup = (CheckGroup)UM01SearchForm.get("apps");

                ListView appListView = new ListView("appList", appList) {

                @Override
                protected void populateItem(ListItem arg0) {
                        Check app = new Check("app", arg0.getModel(), appsCheckGroup);

                        System.out.println("In Ajax ListView.populateItem");

                        ApplL appObject = (ApplL)arg0.getModelObject();
                        app.add(new SimpleAttributeModifier("title",appObject.getApplDc()));        

                        app.setEnabled(false);               

                        arg0.add(app);
                Label lblApp = new Label("lblApp", appObject.getApplCd());
                lblApp.add(new SimpleAttributeModifier("title", appObject.getApplDc()));
                arg0.add(lblApp);
                }
        };

        appListView.setReuseItems(true);
        appsCheckGroup.addOrReplace(appListView);

        System.out.println("In Ajax addComponent");

        target.addComponent(appsCheckGroup.setRenderBodyOnly(false));

        }

}

OUTPUT:
1) None of the checkboxes changes state after the Ajax update (but the Ajax request is processed)
2) The line "In Ajax addComponent" happens BEFORE the line "In Ajax ListView.populateItem"

I've also tried directly accessing the Checks inside the CheckGroup, but that didn't work for me, the state still doesn't change: e.g., for Check #3,

// Direct Access Test
Check c3 = (Check)((ListItem)((ListView)appsCheckGroup.get("appList")).get("3")).get("app");
c3.setEnabled(false);
target.addComponent(c3);


Thanks for any help.
Reply | Threaded
Open this post in threaded view
|

Re: Disabling Individual Checkboxes in CheckGroup

Sven Meier
Hi,

 >1) None of the checkboxes changes state after the Ajax update (but the
Ajax request is processed)

You're calling #setRenderBodyOnly(false) too late. By default CheckGroup
does not render its tag, so you have to enable it for Ajax updates
*before* it is rendered:

   final CheckGroup appsCheckGroup=new CheckGroup("apps");
   appsCheckGroup.setOutputMarkupId(true);
   appsCheckGroup.setRenderBodyOnly(false);
   add(appsCheckGroup);

2) The line "In Ajax addComponent" happens BEFORE the line "In Ajax
ListView.populateItem"

Sure it does. #populateItem() is called when the ListView is rendered to
the Ajax response *after* it was added to the ART.

There's no need to create a new ListView and use #addOrReplace() in
Ajax-Requests. Just update the original ListView:

   private boolean enabled = true;

   final CheckGroup appsCheckGroup=new CheckGroup("apps");
   appsCheckGroup.setOutputMarkupId(true);
   appsCheckGroup.setRenderBodyOnly(false);
   add(appsCheckGroup);

   ListView appListView = new ListView("appList", appList) {
     @Override
     protected ListItem newItem(final int index, IModel itemModel)
     {
         return new ListItem(index, itemModel) {
          protected void onComponentTag(ComponentTag tag) {
            tag.put("title", ((ApplL)itemModel.getObject()).getApplDc());
          }
         };
     }

     @Override
     protected void populateItem(final ListItem arg0) {
       Check app = new Check("app", arg0.getModel(), appsCheckGroup) {
         protected void onConfigure() {
           super.onConfigure();

           setEnabled(enabled);
         }
       };
       arg0.add(app);

       Label lblApp = new Label("lblApp", new
PropertyModel(arg0.getModel(), "applCd"));
       arg0.add(lblApp);
     }
   };
   appListView.setReuseItems(true);
   appsCheckGroup.add(appListView);

Note how all access to the model object is done as late as possible.

The Ajax update is quite simple then:

structureDropDown.add(new AjaxFormComponentUpdatingBehavior("onchange")
{
   public void onUpdate(ART target) {
     enabled != enabled;

     target.addComponent(appsCheckGroup);
   }
}


Hope this helps
Sven


On 04/28/2013 10:59 PM, eugenebalt wrote:

> Here is the full code. This is an urgent problem so any advice much
> appreciated.
>
> ISSUE: Cannot enable/disable Checks in an Ajax update, their state remains
> the same.
>
> The Checks in the CheckGroup are supposed to change depending on a DropDown
> change.
>
> 1) On Page Construction, all Checks in the CheckGroup are initially enabled
>
> final CheckGroup appsCheckGroup=new CheckGroup("apps");
> appsCheckGroup.setOutputMarkupId(true);
> add(appsCheckGroup);
> ListView appListView = new ListView("appList", appList) {
> @Override
> protected void populateItem(ListItem arg0) {
>
> Check app = new Check("app", arg0.getModel(), appsCheckGroup);
> ApplL appObject = (ApplL)arg0.getModelObject();
> app.add(new SimpleAttributeModifier("title",appObject.getApplDc()));
> arg0.add(app);
>
>                           *app.setEnabled(true);*
>
> Label lblApp = new Label("lblApp", appObject.getApplCd());
> lblApp.add(new SimpleAttributeModifier("title", appObject.getApplDc()));
> arg0.add(lblApp);
> }
> };
> appListView.setReuseItems(true);
> appsCheckGroup.add(appListView);
>
>
> 2) In the Ajax Request (invoked from a separate DropDown):
>
> structureDropDown.add(new AjaxFormComponentUpdatingBehavior("onchange")
> {
> final CheckGroup appsCheckGroup = (CheckGroup)UM01SearchForm.get("apps");
>
> ListView appListView = new ListView("appList", appList) {
>
> @Override
> protected void populateItem(ListItem arg0) {
> Check app = new Check("app", arg0.getModel(), appsCheckGroup);
>
> System.out.println("In Ajax ListView.populateItem");
>
> ApplL appObject = (ApplL)arg0.getModelObject();
> app.add(new SimpleAttributeModifier("title",appObject.getApplDc()));        
>
> *app.setEnabled(false);*        
>
> arg0.add(app);
> Label lblApp = new Label("lblApp", appObject.getApplCd());
> lblApp.add(new SimpleAttributeModifier("title", appObject.getApplDc()));
> arg0.add(lblApp);
> }
> };
>
> appListView.setReuseItems(true);
> appsCheckGroup.addOrReplace(appListView);
>
> System.out.println("In Ajax addComponent");
>
> target.addComponent(appsCheckGroup.setRenderBodyOnly(false));
>
> }
>
> }
>
> OUTPUT:
> 1) None of the checkboxes changes state after the Ajax update (but the Ajax
> request is processed)
> 2) The line "In Ajax addComponent" happens BEFORE the line "In Ajax
> ListView.populateItem"
>
> I've also tried directly accessing the Checks inside the CheckGroup, but
> that didn't work for me, the state still doesn't change: e.g., for Check #3,
>
> // Direct Access Test
> Check c3 =
> (Check)((ListItem)((ListView)appsCheckGroup.get("appList")).get("3")).get("app");
> c3.setEnabled(false);
> target.addComponent(c3);
>
>
> Thanks for any help.
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Disabling-Individual-Checkboxes-in-CheckGroup-tp4658165p4658366.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Disabling Individual Checkboxes in CheckGroup

eugenebalt
This post was updated on .
Thanks Sven, let me clarify something in your code:

1) #newItem only has the signature newItem(int); there is no newItem(int,IModel).
2) At the line "super.configure()" we get the error "The method configure() is undefined for the type Check".
3) When you make references to "enabled", I assume it's some global flag/variable that you're checking, which is set outside in the main module?

One other note: List#populateItem() only gets called once, during construction, and doesn't get called again after Ajax. But when we were doing addOrReplace(newListView) it was actually getting called after Ajax.

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Disabling Individual Checkboxes in CheckGroup

Paul Bors
There is the Wicket way of doing thing simple, and then there our own way
of overriding the default behavior of the framework for whatever needs you
might have.

In your case, I think you're overcomplicating things by way too much and
you got yourself in a situation where it involved more work to accomplish
something simple. Your code alone looks a bit too complicated to me for
what is trying to do.

I suggest you step back and list the use-cases you need and then approach
the problem from a different angle.

~ Thank you,
   Paul Bors

On Mon, Apr 29, 2013 at 10:47 AM, eugenebalt <[hidden email]> wrote:

> Thanks Sven, let me clarify something in your code:
>
> 1) #newItem only has the signature newItem(int); there is no
> newItem(int,IModel).
> 2) At the line "super.configure()" we get the error "The method configure()
> is undefined for the type Check".
> 3) When you make references to "enabled", I assume it's some global
> flag/variable that you're checking, which is set outside in the main
> module?
>
> Thanks
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Disabling-Individual-Checkboxes-in-CheckGroup-tp4658165p4658388.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
~ Thank you,
    Paul@Bors.ws
Reply | Threaded
Open this post in threaded view
|

Re: Disabling Individual Checkboxes in CheckGroup

Sven Meier
In reply to this post by eugenebalt
Hi,

I didn't check the code with a compiler so please excuse any errors.

1) see ListView#newItem(int, IModel)
2) see Component#onConfigure()
3) enabled could be a member variable of the containing panel

Regards
Sven


On 04/29/2013 04:47 PM, eugenebalt wrote:

> Thanks Sven, let me clarify something in your code:
>
> 1) #newItem only has the signature newItem(int); there is no
> newItem(int,IModel).
> 2) At the line "super.configure()" we get the error "The method configure()
> is undefined for the type Check".
> 3) When you make references to "enabled", I assume it's some global
> flag/variable that you're checking, which is set outside in the main module?
>
> Thanks
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Disabling-Individual-Checkboxes-in-CheckGroup-tp4658165p4658388.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Disabling Individual Checkboxes in CheckGroup

eugenebalt
Thanks Sven. We don't have the below methods. We are using Wicket 1.4.7, probably time to upgrade.

ListView#newItem(int, IModel)
see Component#onConfigure()


Reply | Threaded
Open this post in threaded view
|

Re: Disabling Individual Checkboxes in CheckGroup

Sven Meier
1.4.7 ... that's really old :/.

Sven

On 04/29/2013 09:13 PM, eugenebalt wrote:

> Thanks Sven. We don't have the below methods. We are using Wicket 1.4.7,
> probably time to upgrade.
>
> ListView#newItem(int, IModel)
> see Component#onConfigure()
>
>
>
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Disabling-Individual-Checkboxes-in-CheckGroup-tp4658165p4658395.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Disabling Individual Checkboxes in CheckGroup

Paul Bors
See the examples for form input and the use of CheckGroup:
http://www.wicket-library.com/wicket-examples/forminput

If you want to "uncheck" or "check" one of your component, either insert or
remove from your collection the element you want checked or not.

~ Thank you,
   Paul Bors
PS: If by now you haven't put together a quick start for yourself to
understand how CheckGroup works in Wicket, then I suggest you do so.
On Mon, Apr 29, 2013 at 3:17 PM, Sven Meier <[hidden email]> wrote:

> 1.4.7 ... that's really old :/.
>
> Sven
>
>
> On 04/29/2013 09:13 PM, eugenebalt wrote:
>
>> Thanks Sven. We don't have the below methods. We are using Wicket 1.4.7,
>> probably time to upgrade.
>>
>> ListView#newItem(int, IModel)
>> see Component#onConfigure()
>>
>>
>>
>>
>>
>>
>> --
>> View this message in context: http://apache-wicket.1842946.**
>> n4.nabble.com/Disabling-**Individual-Checkboxes-in-**
>> CheckGroup-tp4658165p4658395.**html<http://apache-wicket.1842946.n4.nabble.com/Disabling-Individual-Checkboxes-in-CheckGroup-tp4658165p4658395.html>
>> Sent from the Users forum mailing list archive at Nabble.com.
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<[hidden email]>
>> For additional commands, e-mail: [hidden email]
>>
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<[hidden email]>
> For additional commands, e-mail: [hidden email]
>
>
~ Thank you,
    Paul@Bors.ws