Rodrigo
Rodrigo

Reputation: 153

Check or uncheck selectBooleanCheckBox by checking another

I have a , situation: In a JSF page i have some selectBooleanCheckbox. And i needed that, when i check one of them, some others were unchecked. I'm working on this to add or remove columns from a JasperReports report, just to explain why do i need that to work.

Is it possible? If yes, i would like some help to achieve that, thanks.

xhtml:

                    <h:selectBooleanCheckbox value="#{simpleReport.colunaId}" />
                    <h:outputText escape="false" value="Cód." />
                    <h:selectBooleanCheckbox value="#{simpleReport.colunaCliente}" />
                    <h:outputText escape="false" value="Cliente" />
                    <h:selectBooleanCheckbox value="#{simpleReport.colunaCondutor}" />
                    <h:outputText escape="false" value="Condutor" />
                    <h:selectBooleanCheckbox
                        value="#{simpleReport.colunaCondicaoTempo}" />
                    <h:outputText escape="false" value="Cond. Tempo" />
                    <h:selectBooleanCheckbox value="#{simpleReport.colunaOcorrencia}" />
                    <h:outputText escape="false" value="Ocorrência" />
                    <h:selectBooleanCheckbox value="#{simpleReport.colunaStatus}" />
                    <h:outputText escape="false" value="Status" />
                    <h:selectBooleanCheckbox value="#{simpleReport.colunaPeriodo}" />
                    <h:outputText escape="false" value="Período" />
                    <h:selectBooleanCheckbox value="#{simpleReport.colunaSoma}" />
                    <h:outputText escape="false" value="Soma" />
                    <h:selectBooleanCheckbox value="#{simpleReport.colunaQtdCli}" />
                    <h:outputText escape="false" value="QtdCli" />
                    <h:selectBooleanCheckbox value="#{simpleReport.groupByCLiente}" />
                    <h:outputText escape="false" value="Group" />

Bean

boolean colunaId = false, colunaCliente = false, colunaCondutor = false, colunaPeriodo = false,
        colunaCondicaoTempo = false, colunaStatus = false, colunaOcorrencia = false, colunaSoma = false,
        colunaQtdCond = false, colunaQtdCli = false;

boolean groupByCLiente = false, groupByCondutor = false;

I have found this post : Single Select Checkbox Using JSF but it is not the very same case, and i was not able to achieve what i need yet.

For example, if i check "group" it sould uncheck "Ocorrencia" and "Status". enter image description here

Upvotes: 3

Views: 6914

Answers (1)

Smutje
Smutje

Reputation: 18143

You should add a <p:ajax child to the checkboxes who should effect others where you update the respective checkboxes to be affected and add a listener method which resets the respective values of the checkboxes to be affected in your view model. Similar to

page.xhtml

<!-- Should be reset if "2" is selected -->
<p:selectBooleanCheckbox id="1" value="#{view.value1}"/> 

<p:selectBooleanCheckbox id="2" value="#{view.value2}">
    <p:ajax update="1" listener="#{view.resetValue1}"/>
</p:selectBooleanCheckbox>

View.java

public void resetValue1() {
    this.value1 = false;
}

Upvotes: 3

Related Questions