Good morning, everyone, I am having a problem with the handling of two checkboxes which should be mutually exclusive, on the page we cannot put an id because multiselection is provided.
Here the zkoss code:
<cell colspan="2">
<checkbox
label="${labels.label.giaAddebitata}"
checked="@load(each.flagAddebitata eq '1')"
onCheck="@command('addebitata', fladd=event.checked,idPer=each.idPerizia )"
onFocus="@command('manageList', idPer=each.idPerizia)"
disabled="@load(each.statoContabile eq 4 ? true : false)"/>
</cell>
<cell colspan="2">
<checkbox
label="${labels.label.nonAddebitare}"
checked="@load(each.nonAddebitare eq '1')"
onCheck="@command('nonaddebitata',flnoadd=event.checked, idPer=each.idPerizia)"
onFocus="@command('manageList', idPer=each.idPerizia)"
disabled="@load(each.statoContabile eq 4 ? true : false)"/>
</cell>
and the java functions
@Command
@NotifyChange ({ "flagAddebitata","nonAddebitare", "selectedRic"})
public void addebitata(@BindingParam("fladd") boolean fladd,@BindingParam("idPer")int idPerizia ) {
boolean addebitata = fladd;
selectedRic = new HashSet<AddebitoClienteViewDTO>();
for(AddebitoClienteViewDTO add : carList) {
if(add.getIdPerizia() == idPerizia) {
add.setFlagAddebitata(booleanToString.apply(fladd));
selectedRic.add(add);
}
}
logger.debug("SELECTEDRIC non addebitare " + selectedRic);
logger.debug("addebitata funzione " +addebitata);
}
@Command
@NotifyChange ({ "nonAddebitare", "selectedRic"})
public void nonaddebitata(@BindingParam("flnoadd") boolean flnoadd,@BindingParam("idPer")int idPerizia ) {
boolean nonaddebitata = flnoadd;
selectedRic = new HashSet<AddebitoClienteViewDTO>();
for(AddebitoClienteViewDTO add : carList) {
if(add.getIdPerizia() == idPerizia) {
add.setNonAddebitare(booleanToString.apply(flnoadd));
selectedRic.add(add);
}
}
logger.debug("SELECTEDRIC non addebitare " + selectedRic);
logger.debug("nonaddebitata funzione " +nonaddebitata);
}
We tried using the && != "
the !=
alone and adding another binding param to the java functions.
The result we want to achieve is that if one check is clicked the other if it is already selected loses the check.
Alternatively we tried the radiogroup but it does not allow the non-selection of radioboxes, one is always mandatory. Is there a way to clear the radiobutton without a java clear function?
Thanks
That's a lot of code and hard to turn into a reproducing case due to all of the extra objects, so I'll focus more on the functional requirement.
From your description, I understand that what you want to create is a system in which you can either select "A", "B" or "none".
There is some unspecified behavior in there (like if "A" is selected, can I select "B" and automatically clear selection on "A"? Or does having "A" selected mean that "B" is non-selectable).
From your stated requirement, the component I would choose to express that structure is a dropdown menu with 3 choices ("not selected", "A", "B"), but that might not be what you are trying to achieve with the UI design here?
If you want to make something like that using checkboxes, you may want to keep a single state for the selection status, and a command to update the selection status.
See a simple code sample here: https://zkfiddle.org/sample/hb7f7k/1-Another-new-ZK-fiddle
The left 2 checkboxes work on a "unselect others if selected" workflow. The right 2 checkboxes work on a "cannot select others while selected, but can unselect" workflow.
Note: that sample is a "bare minimum" implementation. In a real case, you'd improve it by factorizing the code, making it into a template, etc. rather than declaring these values inline.