I found a solution, but I'm not sure it's the best/most elegant one, there is
a lot of messy code.
Upon selecting a certain AjaxCheckbox A in a ListView, I had to
1) disable AjaxCheckbox B
2) set its value to TRUE
and conversely, upon deselecting A, I had to (1) enable B and (2) set its
value to FALSE.
First of all, I got the Enable/Disable to work by overriding the
AjaxCheckbox's isEnabled. But in order to make that work, I had to use 2
flags. The first flag holds the current value of A, and the second flag
shows that clicking has begun. These are the flags "Clicked" and "Selected",
and they get updated on onUpdate().
// override isEnabled
public boolean isEnabled() {
if (bean.getKey().equals(DELETEOWN)
&& eNotesMgrClicked)
{
if (eNotesMgrSelected)
return false;
else
return true;
}
else
return super.isEnabled();
}
// set the flag that Checkbox A has been clicked and selected/de-selected
@Override
protected void onUpdate(AjaxRequestTarget arg0) {
if (bean.getKey().equals(ADMIN))
{
eNotesMgrClicked = true;
if (getModelObject())
eNotesMgrSelected = true;
else
eNotesMgrSelected = false
}
arg0.addComponent(checkboxDeleteOwn);
}
}
The 2nd issue, actually checking/unchecking the checkbox, was more
difficult. I had to actually save a reference to the AjaxCheckbox I want to
select/de-select. To save it, I overrode onBeforeRender(), and if it was the
right checkbox B, I saved its reference in a variable. Then, I could
reference it in onUpdate() and set its model object.
My questions:
1) I also wanted to do the setEnabled(true)/setEnabled(false) on Checkbox B,
now that I have its reference, as part of onUpdate, but that does NOT work.
Can anyone tell me why this Enable/Disable doesn't work:
if (getModelObject())
{
eNotesMgrSelected = true;
checkboxDeleteOwn.setEnabled(false);
checkboxDeleteOwn.setModelObject(true);
}
else
{
eNotesMgrSelected = false;
checkboxDeleteOwn.setEnabled(true);
checkboxDeleteOwn.setModelObject(false);
}
The setModelObject works on my saved-reference checkboxDeleteOwn, but
setEnabled() does NOT work.
2) This code is pretty messy, is there any better way to disable and set
individual AjaxCheckboxes based on the action of another AjaxCheckbox?
--
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/Select-AjaxCheckbox-from-Another-AjaxCheckbox-inside-ListView-tp4659829p4659872.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]