Re: Check Group selected items called from other form loses the checked values

2016-10-26 Thread ganea iulia
Thank you so much for these examples.
This is great.

On Thu, Oct 20, 2016 at 2:22 PM, Francois Meillet <
francois.meil...@gmail.com> wrote:

> Hi,
>
> Use a ListView.
>
> The model of the second form is not updated until the form is submitted.
> You need to perform a submit if you want to see this model updated, and
> the correct value for tst.getCheckedTestBeans().size().
>
> If you want to avoid the manual submit phase, you need to use Ajax.
>
> Please find here your code slightly modified.
>
> TestPage
> http://pastebin.com/DYNpeZLt
> TestPage.html
> http://pastebin.com/gFa6Z5ZS
> ModelForForm
> http://pastebin.com/EhjezBWJ
> Wrapper
> http://pastebin.com/8B7n68VH
>
>
> François
>
>
>
>
> > Le 20 oct. 2016 à 08:38, ganea iulia  a écrit :
> >
> > Hello, Thank you for the samples.
> > But I will explain again what I have:
> >
> > I have two forms on my page.
> > In the bottom form I have a RefreshingView component, with check all
> > checkbox in the header, and check components for each items.
> > In the top form there is a link, where I need to get the checked items
> from
> > the second form (the bottom form);
> >
> > This is what I have done:
> > For checkAll and the individual checks I have used CheckGroup,
> > CheckGroupSelector and Check.
> >
> > The issue is that because the refreshing view refreshes the model at
> every
> > server roundtrip, when I check on item, the check doesn't maintain it's
> > value, because it receives every time a new model.
> >
> > So this bit from the RefreshingView always returns a new model which
> makes
> > the checks to dissapera:
> > @Override
> > protected Iterator getItemModels() {
> > List lst = SpringCtx.getAppDB(TestBeanDao.class).selectAll();
> > List models = new ArrayList();
> > for (TestBean tstSN:lst) {
> > IModel modTst = new Model(tstSN);
> > models.add(modTst);
> > }
> > return models.iterator();
> > }
> >
> >
> > Isn;t there any way that I can still use the CheckGroup and Check
> > components? As this comes easy when it is needed a CheckAll
> functionality.
> >
> > Thank you
> >
> > Here is the code:
> >
> > =Java code=
> >
> > private static final long serialVersionUID = 311508940740808005L;
> > private static final Logger logger = LogManager.getLogger(TestPage.
> class);
> > private TestForm tst;
> > public TestPage(IModel model) {
> > super(model);
> >
> > TestForm0 tst0 = new TestForm0("testForm0");
> > tst0.setOutputMarkupId(true);
> > add(tst0);
> > tst = new TestForm("testForm", model);
> > tst.setOutputMarkupId(true);
> > add(tst);
> >
> >
> > }
> >
> > class TestForm0 extends Form {
> >
> > /**
> > *
> > */
> > private static final long serialVersionUID = 1L;
> >
> > public TestForm0(String id) {
> > super(id);
> >
> > Link print = new Link("print") {
> > private static final long serialVersionUID = 15L;
> >
> > @Override
> > public void onClick() {
> > System.out.println("size=" + tst.getCheckedTestBeans().size());
> > }
> > };
> > add(print);
> > }
> > }
> > class TestForm extends Form {
> > /**
> > *
> > */
> > private static final long serialVersionUID = 1L;
> >
> > private List checkedTestBeans;
> > public List getCheckedTestBeans() {
> > return checkedTestBeans;
> > }
> >
> > public void setCheckedTestBeans(List checkedTestBeans) {
> > this.checkedTestBeans = checkedTestBeans;
> > }
> >
> > public TestForm(String id, IModel model) {
> > super(id, model);
> >
> > checkedTestBeans = new ArrayList();
> > TextField txtName = new TextField("txtName", new
> > PropertyModel(getModelObject(), "name"));
> > add(txtName);
> > txtName.setOutputMarkupId(true);
> > txtName.add(new AjaxFormComponentUpdatingBehavior("change") {
> > private static final long serialVersionUID = 1654345477970524731L;
> >
> > @Override
> > protected void onUpdate(AjaxRequestTarget target) {
> > target.add(txtName);
> > }
> >
> > });
> >
> > ///
> > CheckGroup group = new CheckGroup("group1",
> > checkedTestBeans);
> > group.setOutputMarkupId(true);
> > group.add(new AjaxFormChoiceComponentUpdatingBehavior() {
> > private static final long serialVersionUID = 1654345477970524731L;
> >
> > @Override
> > protected void onUpdate(AjaxRequestTarget target) {
> > target.add(group);
> > }
> >
> > });
> > CheckGroupSelector cgs = new CheckGroupSelector("allCheck1");
> > group.add(cgs);
> > final WebMarkupContainer itemsContainer = new
> > WebMarkupContainer("itemsContainer1");
> > itemsContainer.setOutputMarkupId(true);
> > itemsContainer.add(new RefreshingView("forEachItem1") {
> > /**
> > *
> > */
> > private static final long serialVersionUID = 1L;
> > @Override
> > protected Iterator getItemModels() {
> > List lst = SpringCtx.getAppDB(TestBeanDao.class).selectAll();
> > List models = new ArrayList();
> > for (TestBean tstSN:lst) {
> > IModel modTst = new Model(tstSN);
> > models.add(modTst);
> > }
> > return models.iterator();
> > }
> >
> > @Override
> > protected void populateItem(Item item) {
> >
> >  

Re: Check Group selected items called from other form loses the checked values

2016-10-20 Thread Francois Meillet
Hi,

Use a ListView.

The model of the second form is not updated until the form is submitted.
You need to perform a submit if you want to see this model updated, and the 
correct value for tst.getCheckedTestBeans().size().

If you want to avoid the manual submit phase, you need to use Ajax.

Please find here your code slightly modified.

TestPage
http://pastebin.com/DYNpeZLt
TestPage.html
http://pastebin.com/gFa6Z5ZS
ModelForForm
http://pastebin.com/EhjezBWJ
Wrapper
http://pastebin.com/8B7n68VH


François




> Le 20 oct. 2016 à 08:38, ganea iulia  a écrit :
> 
> Hello, Thank you for the samples.
> But I will explain again what I have:
> 
> I have two forms on my page.
> In the bottom form I have a RefreshingView component, with check all
> checkbox in the header, and check components for each items.
> In the top form there is a link, where I need to get the checked items from
> the second form (the bottom form);
> 
> This is what I have done:
> For checkAll and the individual checks I have used CheckGroup,
> CheckGroupSelector and Check.
> 
> The issue is that because the refreshing view refreshes the model at every
> server roundtrip, when I check on item, the check doesn't maintain it's
> value, because it receives every time a new model.
> 
> So this bit from the RefreshingView always returns a new model which makes
> the checks to dissapera:
> @Override
> protected Iterator getItemModels() {
> List lst = SpringCtx.getAppDB(TestBeanDao.class).selectAll();
> List models = new ArrayList();
> for (TestBean tstSN:lst) {
> IModel modTst = new Model(tstSN);
> models.add(modTst);
> }
> return models.iterator();
> }
> 
> 
> Isn;t there any way that I can still use the CheckGroup and Check
> components? As this comes easy when it is needed a CheckAll functionality.
> 
> Thank you
> 
> Here is the code:
> 
> =Java code=
> 
> private static final long serialVersionUID = 311508940740808005L;
> private static final Logger logger = LogManager.getLogger(TestPage.class);
> private TestForm tst;
> public TestPage(IModel model) {
> super(model);
> 
> TestForm0 tst0 = new TestForm0("testForm0");
> tst0.setOutputMarkupId(true);
> add(tst0);
> tst = new TestForm("testForm", model);
> tst.setOutputMarkupId(true);
> add(tst);
> 
> 
> }
> 
> class TestForm0 extends Form {
> 
> /**
> *
> */
> private static final long serialVersionUID = 1L;
> 
> public TestForm0(String id) {
> super(id);
> 
> Link print = new Link("print") {
> private static final long serialVersionUID = 15L;
> 
> @Override
> public void onClick() {
> System.out.println("size=" + tst.getCheckedTestBeans().size());
> }
> };
> add(print);
> }
> }
> class TestForm extends Form {
> /**
> *
> */
> private static final long serialVersionUID = 1L;
> 
> private List checkedTestBeans;
> public List getCheckedTestBeans() {
> return checkedTestBeans;
> }
> 
> public void setCheckedTestBeans(List checkedTestBeans) {
> this.checkedTestBeans = checkedTestBeans;
> }
> 
> public TestForm(String id, IModel model) {
> super(id, model);
> 
> checkedTestBeans = new ArrayList();
> TextField txtName = new TextField("txtName", new
> PropertyModel(getModelObject(), "name"));
> add(txtName);
> txtName.setOutputMarkupId(true);
> txtName.add(new AjaxFormComponentUpdatingBehavior("change") {
> private static final long serialVersionUID = 1654345477970524731L;
> 
> @Override
> protected void onUpdate(AjaxRequestTarget target) {
> target.add(txtName);
> }
> 
> });
> 
> ///
> CheckGroup group = new CheckGroup("group1",
> checkedTestBeans);
> group.setOutputMarkupId(true);
> group.add(new AjaxFormChoiceComponentUpdatingBehavior() {
> private static final long serialVersionUID = 1654345477970524731L;
> 
> @Override
> protected void onUpdate(AjaxRequestTarget target) {
> target.add(group);
> }
> 
> });
> CheckGroupSelector cgs = new CheckGroupSelector("allCheck1");
> group.add(cgs);
> final WebMarkupContainer itemsContainer = new
> WebMarkupContainer("itemsContainer1");
> itemsContainer.setOutputMarkupId(true);
> itemsContainer.add(new RefreshingView("forEachItem1") {
> /**
> *
> */
> private static final long serialVersionUID = 1L;
> @Override
> protected Iterator getItemModels() {
> List lst = SpringCtx.getAppDB(TestBeanDao.class).selectAll();
> List models = new ArrayList();
> for (TestBean tstSN:lst) {
> IModel modTst = new Model(tstSN);
> models.add(modTst);
> }
> return models.iterator();
> }
> 
> @Override
> protected void populateItem(Item item) {
> 
>  item.add(new Label("itemName", new
> PropertyModel(item.getModel(), "name")));
>  item.add(new Label("itemCode", new
> PropertyModel(item.getModel(), "code")));
>  item.add(new Label("itemId", new PropertyModel(item.getModel(),
> "id")));
>  Check chk = new Check("itemCheck", item.getModel(),
> group);
> 
>  item.add(chk);
> }
>  });
> group.add(itemsContainer);
> add(group);
> }
> 
> @Override
> protected void onSubmit() {
> 
> logger.info 

Re: Check Group selected items called from other form loses the checked values

2016-10-20 Thread ganea iulia
Hello, Thank you for the samples.
But I will explain again what I have:

I have two forms on my page.
In the bottom form I have a RefreshingView component, with check all
checkbox in the header, and check components for each items.
In the top form there is a link, where I need to get the checked items from
the second form (the bottom form);

This is what I have done:
For checkAll and the individual checks I have used CheckGroup,
CheckGroupSelector and Check.

The issue is that because the refreshing view refreshes the model at every
server roundtrip, when I check on item, the check doesn't maintain it's
value, because it receives every time a new model.

So this bit from the RefreshingView always returns a new model which makes
the checks to dissapera:
@Override
protected Iterator getItemModels() {
List lst = SpringCtx.getAppDB(TestBeanDao.class).selectAll();
List models = new ArrayList();
for (TestBean tstSN:lst) {
IModel modTst = new Model(tstSN);
models.add(modTst);
}
return models.iterator();
}


Isn;t there any way that I can still use the CheckGroup and Check
components? As this comes easy when it is needed a CheckAll functionality.

Thank you

Here is the code:

=Java code=

private static final long serialVersionUID = 311508940740808005L;
private static final Logger logger = LogManager.getLogger(TestPage.class);
private TestForm tst;
public TestPage(IModel model) {
super(model);

TestForm0 tst0 = new TestForm0("testForm0");
tst0.setOutputMarkupId(true);
add(tst0);
tst = new TestForm("testForm", model);
tst.setOutputMarkupId(true);
add(tst);


}

class TestForm0 extends Form {

/**
*
*/
private static final long serialVersionUID = 1L;

public TestForm0(String id) {
super(id);

Link print = new Link("print") {
private static final long serialVersionUID = 15L;

@Override
public void onClick() {
System.out.println("size=" + tst.getCheckedTestBeans().size());
}
};
add(print);
}
}
class TestForm extends Form {
/**
*
*/
private static final long serialVersionUID = 1L;

private List checkedTestBeans;
public List getCheckedTestBeans() {
return checkedTestBeans;
}

public void setCheckedTestBeans(List checkedTestBeans) {
this.checkedTestBeans = checkedTestBeans;
}

public TestForm(String id, IModel model) {
super(id, model);

checkedTestBeans = new ArrayList();
TextField txtName = new TextField("txtName", new
PropertyModel(getModelObject(), "name"));
add(txtName);
txtName.setOutputMarkupId(true);
txtName.add(new AjaxFormComponentUpdatingBehavior("change") {
private static final long serialVersionUID = 1654345477970524731L;

@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(txtName);
}

});

///
CheckGroup group = new CheckGroup("group1",
checkedTestBeans);
group.setOutputMarkupId(true);
group.add(new AjaxFormChoiceComponentUpdatingBehavior() {
private static final long serialVersionUID = 1654345477970524731L;

@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(group);
}

});
CheckGroupSelector cgs = new CheckGroupSelector("allCheck1");
group.add(cgs);
final WebMarkupContainer itemsContainer = new
WebMarkupContainer("itemsContainer1");
itemsContainer.setOutputMarkupId(true);
itemsContainer.add(new RefreshingView("forEachItem1") {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
protected Iterator getItemModels() {
List lst = SpringCtx.getAppDB(TestBeanDao.class).selectAll();
List models = new ArrayList();
for (TestBean tstSN:lst) {
IModel modTst = new Model(tstSN);
models.add(modTst);
}
return models.iterator();
}

@Override
protected void populateItem(Item item) {

  item.add(new Label("itemName", new
PropertyModel(item.getModel(), "name")));
  item.add(new Label("itemCode", new
PropertyModel(item.getModel(), "code")));
  item.add(new Label("itemId", new PropertyModel(item.getModel(),
"id")));
  Check chk = new Check("itemCheck", item.getModel(),
group);

  item.add(chk);
}
  });
group.add(itemsContainer);
add(group);
}

@Override
protected void onSubmit() {

logger.info("OnSubmit");
System.out.println("size=" + checkedTestBeans.size());

}
}


=HTML=
 
   












Name
Code


Id





   








   





   





On Wed, Oct 19, 2016 at 7:24 PM, Francois Meillet <
francois.meil...@gmail.com> wrote:

> Have a look at
>
> https://cwiki.apache.org/confluence/display/WICKET/
> Listview+with+checkboxes  confluence/display/WICKET/Listview+with+checkboxes>
>
> https://www.mkyong.com/wicket/wicket-multiple-checkboxes-example-
> checkboxmultiplechoice/  checkboxes-example-checkboxmultiplechoice/>
>
>
>
> François
>
>
>
> > Le 19 oct. 2016 à 16:11, ganea iulia  a écrit :
> >
> > Hello,
> >
> > I have actually made this to work by adding this behaviour to the
> > checkgroup:
> >
> > group.add(new AjaxFormChoiceComponentUpdatingBehavior() {
> >private static final long serialVersionUID 

Re: Check Group selected items called from other form loses the checked values

2016-10-19 Thread Francois Meillet
Have a look at 

https://cwiki.apache.org/confluence/display/WICKET/Listview+with+checkboxes 


https://www.mkyong.com/wicket/wicket-multiple-checkboxes-example-checkboxmultiplechoice/
 




François



> Le 19 oct. 2016 à 16:11, ganea iulia  a écrit :
> 
> Hello,
> 
> I have actually made this to work by adding this behaviour to the
> checkgroup:
> 
> group.add(new AjaxFormChoiceComponentUpdatingBehavior() {
>private static final long serialVersionUID =
> 1654345477970524731L;
> 
>@Override
>protected void onUpdate(AjaxRequestTarget target) {
>target.add(group);
>}
> 
>});
> 
> However, now I face following issue:
> If I replace my ListView component, with a RefreshingView, I cannot check
> any of the checks from the items. I check it, but then it gets unchecked
> right away.
> This is because the RefreshingView repaints its model at every roundtrip to
> the server.
> 
> I have tried this:
> http://stackoverflow.com/questions/12282492/add-row-to-refreshingview-without-repainting-entire-refreshingview
> by setting:
> listOfItems.setItemReuseStrategy(new ReuseIfModelsEqualStrategy());
> 
> But it did not change a thing for me.
> 
> Please guide on how to have a Check for every item of the RepeatingView,
> that can be checked.
> 
> Thank you.
> 
> 
> 
> On Tue, Oct 18, 2016 at 1:28 PM, ganea iulia  wrote:
> 
>> Hi,
>> I have 2 forms.
>> 
>> Bottom form = testForm
>> - I have a listview with checkboxes.
>> As I needed a checkAll control also, I have uses CheckGroup,
>> CheckGroupSelector and Check wicket components.
>> 
>> Top form = testForm0
>> -I have only an link
>> 
>> The use case is the following:
>> I check one item (or all) in bottom form, but then I need to get the
>> selected values when click on link in top form.
>> 
>> The check doesn't do submit so the values are not retained. I alsways get
>> the
>> size = 0 message.
>> 
>> Could you tell me how I can manage this?
>> 
>> Here is the code:
>> =HTML=
>> 
>>   > width="100%">
>> 
>> 
>> > />
>> 
>> 
>> 
>>
>> 
>> 
>> > width="100%">
>> 
>> 
>> Name
>> Code
>> 
>> 
>> Id
>> 
>> 
>> 
>> 
>> 
>>   
>> 
>> 
>> 
>> 
>> 
>> > />
>> 
>> 
>>   
>> 
>> 
>> 
>> > name="btnSave" value="OK" />
>> 
>>   
>> 
>> 
>> 
>> 
>> 
>> 
>> ==JAVA==
>> private static final long serialVersionUID = 311508940740808005L;
>> private static final Logger logger = LogManager.getLogger(TestPage.class);
>> private TestForm tst;
>> 
>> public TestPage(IModel model) {
>> super(model);
>> 
>> TestForm0 tst0 = new TestForm0("testForm0");
>> tst0.setOutputMarkupId(true);
>> add(tst0);
>> tst = new TestForm("testForm", model);
>> tst.setOutputMarkupId(true);
>> add(tst);
>> 
>> }
>> 
>> class TestForm0 extends Form {
>> 
>> /**
>> *
>> */
>> private static final long serialVersionUID = 1L;
>> 
>> public TestForm0(String id) {
>> super(id);
>> 
>> Link print = new Link("print") {
>> private static final long serialVersionUID = 15L;
>> 
>> @Override
>> public void onClick() {
>> System.out.println("size=" + tst.getCheckedTestBeans().size());
>> }
>> };
>> add(print);
>> }
>> }
>> class TestForm extends Form {
>> /**
>> *
>> */
>> private static final long serialVersionUID = 1L;
>> 
>> private List checkedTestBeans;
>> public List getCheckedTestBeans() {
>> return checkedTestBeans;
>> }
>> 
>> public void setCheckedTestBeans(List checkedTestBeans) {
>> this.checkedTestBeans = checkedTestBeans;
>> }
>> 
>> public TestForm(String id, IModel model) {
>> super(id, model);
>> 
>> checkedTestBeans = new ArrayList();
>> TextField txtName = new TextField("txtName", new
>> PropertyModel(getModelObject(), "name"));
>> add(txtName);
>> txtName.setOutputMarkupId(true);
>> txtName.add(new AjaxFormComponentUpdatingBehavior("change") {
>> private static final long serialVersionUID = 1654345477970524731L;
>> 
>> @Override
>> protected void onUpdate(AjaxRequestTarget target) {
>> target.add(txtName);
>> }
>> 
>> });
>> 
>> SubmitLink clearForm = new SubmitLink("clearForm", this){
>> 
>> /**
>> *
>> */
>> private static final long serialVersionUID = 1L;
>> @Override
>> public void onSubmit() {
>> model.setObject(new TestBean());
>> TestForm.this.clearInput();
>> };
>> };
>> clearForm.setOutputMarkupId(true);
>> add(clearForm);
>> AjaxLink clearLink = new AjaxLink("clearLink", model)
>> {
>> /**
>> *
>> */
>> private static final long serialVersionUID = 1L;
>> 
>> @Override
>> public void onClick(AjaxRequestTarget target) {
>> model.setObject(new TestBean());
>> TestForm.this.clearInput();
>> target.add(TestForm.this);
>> txtName.setConvertedInput("");
>> 
>> }
>> 
>> };
>> clearLink.setOutputMarkupId(true);
>> add(clearLink);
>> ///
>> CheckGroup group = new CheckGroup("group",
>> 

Re: Check Group selected items called from other form loses the checked values

2016-10-19 Thread ganea iulia
Hello,

I have actually made this to work by adding this behaviour to the
checkgroup:

group.add(new AjaxFormChoiceComponentUpdatingBehavior() {
private static final long serialVersionUID =
1654345477970524731L;

@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(group);
}

});

However, now I face following issue:
If I replace my ListView component, with a RefreshingView, I cannot check
any of the checks from the items. I check it, but then it gets unchecked
right away.
This is because the RefreshingView repaints its model at every roundtrip to
the server.

I have tried this:
http://stackoverflow.com/questions/12282492/add-row-to-refreshingview-without-repainting-entire-refreshingview
by setting:
listOfItems.setItemReuseStrategy(new ReuseIfModelsEqualStrategy());

But it did not change a thing for me.

Please guide on how to have a Check for every item of the RepeatingView,
that can be checked.

Thank you.



On Tue, Oct 18, 2016 at 1:28 PM, ganea iulia  wrote:

> Hi,
> I have 2 forms.
>
> Bottom form = testForm
> - I have a listview with checkboxes.
> As I needed a checkAll control also, I have uses CheckGroup,
> CheckGroupSelector and Check wicket components.
>
> Top form = testForm0
> -I have only an link
>
> The use case is the following:
> I check one item (or all) in bottom form, but then I need to get the
> selected values when click on link in top form.
>
> The check doesn't do submit so the values are not retained. I alsways get
> the
> size = 0 message.
>
> Could you tell me how I can manage this?
>
> Here is the code:
> =HTML=
> 
> width="100%">
> 
> 
>  />
> 
> 
> 
> 
> 
> 
>  width="100%">
> 
> 
> Name
> Code
> 
> 
> Id
> 
> 
> 
> 
> 
>
> 
> 
> 
> 
> 
>  />
> 
> 
>
> 
> 
> 
>  name="btnSave" value="OK" />
> 
>
> 
> 
> 
> 
>
>
> ==JAVA==
> private static final long serialVersionUID = 311508940740808005L;
> private static final Logger logger = LogManager.getLogger(TestPage.class);
> private TestForm tst;
>
> public TestPage(IModel model) {
> super(model);
>
> TestForm0 tst0 = new TestForm0("testForm0");
> tst0.setOutputMarkupId(true);
> add(tst0);
> tst = new TestForm("testForm", model);
> tst.setOutputMarkupId(true);
> add(tst);
>
> }
>
> class TestForm0 extends Form {
>
> /**
> *
> */
> private static final long serialVersionUID = 1L;
>
> public TestForm0(String id) {
> super(id);
>
> Link print = new Link("print") {
> private static final long serialVersionUID = 15L;
>
> @Override
> public void onClick() {
> System.out.println("size=" + tst.getCheckedTestBeans().size());
> }
> };
> add(print);
> }
> }
> class TestForm extends Form {
> /**
> *
> */
> private static final long serialVersionUID = 1L;
>
> private List checkedTestBeans;
> public List getCheckedTestBeans() {
> return checkedTestBeans;
> }
>
> public void setCheckedTestBeans(List checkedTestBeans) {
> this.checkedTestBeans = checkedTestBeans;
> }
>
> public TestForm(String id, IModel model) {
> super(id, model);
>
> checkedTestBeans = new ArrayList();
> TextField txtName = new TextField("txtName", new
> PropertyModel(getModelObject(), "name"));
> add(txtName);
> txtName.setOutputMarkupId(true);
> txtName.add(new AjaxFormComponentUpdatingBehavior("change") {
> private static final long serialVersionUID = 1654345477970524731L;
>
> @Override
> protected void onUpdate(AjaxRequestTarget target) {
> target.add(txtName);
> }
>
> });
>
> SubmitLink clearForm = new SubmitLink("clearForm", this){
>
> /**
> *
> */
> private static final long serialVersionUID = 1L;
> @Override
> public void onSubmit() {
> model.setObject(new TestBean());
> TestForm.this.clearInput();
> };
> };
> clearForm.setOutputMarkupId(true);
> add(clearForm);
> AjaxLink clearLink = new AjaxLink("clearLink", model)
> {
> /**
> *
> */
> private static final long serialVersionUID = 1L;
>
> @Override
> public void onClick(AjaxRequestTarget target) {
> model.setObject(new TestBean());
> TestForm.this.clearInput();
> target.add(TestForm.this);
> txtName.setConvertedInput("");
>
> }
>
> };
> clearLink.setOutputMarkupId(true);
> add(clearLink);
> ///
> CheckGroup group = new CheckGroup("group",
> checkedTestBeans);
> CheckGroupSelector cgs = new CheckGroupSelector("allCheck");
> group.add(cgs);
> List beans = Arrays.asList(new TestBean("Name1", "Code1", 1),
> new TestBean("Name2", "Code2", 2));
> final WebMarkupContainer itemsContainer = new WebMarkupContainer("
> itemsContainer");
> itemsContainer.setOutputMarkupId(true);
> itemsContainer.add(new ListView("forEachItem", beans) {
> /**
> *
> */
> private static final long serialVersionUID = 1L;
>
> @Override
> protected void populateItem(ListItem item) {
>   item.add(new Label("itemName", new PropertyModel(item.getModel(),
> "name")));
>   item.add(new Label("itemCode", new PropertyModel(item.getModel(),
> "code")));
>   item.add(new Label("itemId", new 

Check Group selected items called from other form loses the checked values

2016-10-18 Thread ganea iulia
Hi,
I have 2 forms.

Bottom form = testForm
- I have a listview with checkboxes.
As I needed a checkAll control also, I have uses CheckGroup,
CheckGroupSelector and Check wicket components.

Top form = testForm0
-I have only an link

The use case is the following:
I check one item (or all) in bottom form, but then I need to get the
selected values when click on link in top form.

The check doesn't do submit so the values are not retained. I alsways get
the
size = 0 message.

Could you tell me how I can manage this?

Here is the code:
=HTML=

   












Name
Code


Id





   








   





   






==JAVA==
private static final long serialVersionUID = 311508940740808005L;
private static final Logger logger = LogManager.getLogger(TestPage.class);
private TestForm tst;

public TestPage(IModel model) {
super(model);

TestForm0 tst0 = new TestForm0("testForm0");
tst0.setOutputMarkupId(true);
add(tst0);
tst = new TestForm("testForm", model);
tst.setOutputMarkupId(true);
add(tst);

}

class TestForm0 extends Form {

/**
*
*/
private static final long serialVersionUID = 1L;

public TestForm0(String id) {
super(id);

Link print = new Link("print") {
private static final long serialVersionUID = 15L;

@Override
public void onClick() {
System.out.println("size=" + tst.getCheckedTestBeans().size());
}
};
add(print);
}
}
class TestForm extends Form {
/**
*
*/
private static final long serialVersionUID = 1L;

private List checkedTestBeans;
public List getCheckedTestBeans() {
return checkedTestBeans;
}

public void setCheckedTestBeans(List checkedTestBeans) {
this.checkedTestBeans = checkedTestBeans;
}

public TestForm(String id, IModel model) {
super(id, model);

checkedTestBeans = new ArrayList();
TextField txtName = new TextField("txtName", new
PropertyModel(getModelObject(), "name"));
add(txtName);
txtName.setOutputMarkupId(true);
txtName.add(new AjaxFormComponentUpdatingBehavior("change") {
private static final long serialVersionUID = 1654345477970524731L;

@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(txtName);
}

});

SubmitLink clearForm = new SubmitLink("clearForm", this){

/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public void onSubmit() {
model.setObject(new TestBean());
TestForm.this.clearInput();
};
};
clearForm.setOutputMarkupId(true);
add(clearForm);
AjaxLink clearLink = new AjaxLink("clearLink", model)
{
/**
*
*/
private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
model.setObject(new TestBean());
TestForm.this.clearInput();
target.add(TestForm.this);
txtName.setConvertedInput("");

}

};
clearLink.setOutputMarkupId(true);
add(clearLink);
///
CheckGroup group = new CheckGroup("group",
checkedTestBeans);
CheckGroupSelector cgs = new CheckGroupSelector("allCheck");
group.add(cgs);
List beans = Arrays.asList(new TestBean("Name1", "Code1", 1),
new TestBean("Name2", "Code2", 2));
final WebMarkupContainer itemsContainer = new
WebMarkupContainer("itemsContainer");
itemsContainer.setOutputMarkupId(true);
itemsContainer.add(new ListView("forEachItem", beans) {
/**
*
*/
private static final long serialVersionUID = 1L;

@Override
protected void populateItem(ListItem item) {
  item.add(new Label("itemName", new PropertyModel(item.getModel(),
"name")));
  item.add(new Label("itemCode", new PropertyModel(item.getModel(),
"code")));
  item.add(new Label("itemId", new PropertyModel(item.getModel(), "id")));
  item.add(new Check("itemCheck", item.getModel(), group));
}
  });
group.add(itemsContainer);
add(group);
//choice
List lst = new ArrayList();
lst.add("C1");
lst.add("C2");


ChoiceRenderer renderer = new ChoiceRenderer("code") {

private static final long serialVersionUID = 8875819661197521211L;

@Override
public Object getDisplayValue(String arg0) {
return (arg0.equals("C1") ? "Code1" : "Code2");
}

@Override
public String getIdValue(String arg0, int arg1) {
return arg0;
}

@Override
public String getObject(String paramString, IModel> paramIModel) {
// TODO Auto-generated method stub
return paramString;
}

};
DropDownChoice code = new DropDownChoice("code", lst,
renderer);
code.setOutputMarkupId(true);
code.setModel(new PropertyModel(getModelObject(), "code"));
add(code);
}

@Override
protected void onSubmit() {

logger.info("OnSubmit");
System.out.println("size=" + checkedTestBeans.size());

}
}