I have the same use case only a lot more complicated (nested list views in different panels).
The easier way to auto-select or auto-deselect (aka change the model object) is to share a CompoundPropertyModel across your component hierarchy. In this way a single component can interact with its model object and have access to everything on the page. Then it becomes a matter of adding the component you want to refresh to the AjaxRequestTarget. On Thu, Jun 27, 2013 at 1:58 PM, eugenebalt <eugeneb...@yahoo.com> wrote: > 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: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > >