I have a scenario, that if i check one check box the other should be unchecked.
I am using JSF.
My Code:
<p:dataTable>
<p:column headerText="PAID">
<p:selectBooleanCheckbox value="#{bean.paid}" />
</p:column>
<p:column headerText="NOT PAID">
<p:selectBooleanCheckbox value="#{bean.notPaid}"/>
</p:column>
</p:dataTable>
Clear View:
How can i achieve this!
@Mr.J4mes had worked .
I tried with the same approach but with <p:selectBooleanCheckbox>
.
Code
<p:column id="paid" headerText="Paid">
<p:selectBooleanCheckbox id="paidCheckBox" value="#{bean.paid}">
<p:ajax update="notPaidCheckBox" listener="#{bean.onPaidStatusChange}" />
</p:selectBooleanCheckbox>
</p:column>
<p:column id="notPaid" headerText="NotPaid">
<p:selectBooleanCheckbox id="notPaidCheckBox" value="#{bean.notPaid}">
<p:ajax update="paidCheckBox" listener="#{bean.onNotPaidStatusChange}" />
</p:selectBooleanCheckbox>
</p:column>
@ManagedBean(name="bean")
@SessionScoped
public class Bean {
private boolean paid;
private boolean notpaid;
@PostConstruct
public void Bean() {
this.paid= true;
}
public void onPaidStatusChange() {
if (paid) notpaid= false;
}
public void onNotPaidStatusChange() {
if (notpaid) paid= false;
}
}
This worked Fine. Thanks for Mr.J4mes approach ;-)