6

I have component and I'm trying disable panelGrid below.

<h:selectBooleanCheckbox id="checkboxId" value="#{bean.checked}">
    <p:ajax update="panelId" event="click"/>                                    
</h:selectBooleanCheckbox>
<h:panelGrid id="panelId" rendered="#{!bean.checked}">
    <h:outputLabel>some text</h:outputLabel>
    <h:outputLabel>#registrationBB.registrationModel.homeAddress.actualAddressMathWithRegistration}</h:outputLabel>
</h:panelGrid>

As a result the clicking on checkbox doesn't take no effect. The check indicator doesn't even appear on checkbox component and value bean:checked doesn't sent to the server. I tried to use also. Check indicator appeared but the panel is not refreshed

How to use update via checkbox right?

Nawa
  • 2,058
  • 8
  • 26
  • 48

2 Answers2

14

The example below is what I got to work:

<h:form>
    <h:selectBooleanCheckbox id="checkboxId" value="#{indexBean.checked}" >
        <p:ajax event="change" update="panelId" />
    </h:selectBooleanCheckbox>

    <h:panelGrid id="panelId" style="border:solid 1px black;" >
        <h:outputLabel rendered="#{!indexBean.checked}" >some text</h:outputLabel>
        <h:outputText rendered="#{!indexBean.checked}" value="some text 2" />
    </h:panelGrid>
</h:form>

I had to change the <p:ajax> event from click to change to get the checkbox working. The other issue is if you don't render the <h:panelGrid> the id can not be found to update, so you want to move the rendered attribute to the components inside your <h:panelGrid> but still update the <h:panelGrid>.

Mark
  • 16,772
  • 9
  • 42
  • 55
  • 1
    What version of Primefaces are you using? This doesn't work in version 4, the panelGrid is unaffected no matter if the checkbox is checked or not. – Cenobyte321 Jun 19 '14 at 00:32
  • 1
    @Nab Probably version 3.x something. This question was asked years before 4.0 was released. – Mark Jun 19 '14 at 00:48
  • 1
    I had similar issues with a custom jsf component in 5.0, I solved it by wrapping it in a panel and updating the panel instead. Could try that. – Chris Jan 28 '15 at 18:43
  • @MarkRobinson This was the catch The other issue is if you don't render the `` the id can not be found to update, so you want to move the rendered attribute to the components inside your `` – M. Atif Riaz Nov 11 '15 at 12:55
0

A slight variation. Your backing bean field doesn't have to be a boolean. If you had a backing bean with fields:

private List<SelectItem> myStringList;
private String myString;

then you initialize myStringList like this before the form load:

myStringList = Arrays.asList(new SelectItem("one", "The Number One"),
                new SelectItem("two", "The number two")
        );

then you could do this:

<h:form>
    <p:selectOneRadio id="ctlSearchType" value="#{mybean.myString}"  layout="grid" columns="3">
       <f:selectItems value="#{mybean.myStringList}" />
       <p:ajax event="change" update="ctlone,ctltwo"/>
    </p:selectOneRadio>

    <h:panelGrid id="panelId" style="border:solid 1px black;" >
       <p:outputLabel for="ctlone" value="Field one:"/>
       <p:inputText value="#{mybean.whatever}" id="ctlone" size="8" maxlength="10" disabled="#{mybean.myString eq 'one'}"/>
       <p:outputLabel for="ctltwo" value="Field two:"/>
       <p:inputText value="#{mybean.whatevertwo}" id="ctltwo" size="8" maxlength="10" disabled="#{mybean.myString eq 'two'}"/>                         
    </h:panelGrid>
</h:form>
nettie
  • 628
  • 1
  • 11
  • 23
  • Using 'SelectItem' is sort of not very common anymore since normal lists are supported too and a selectOneRadio is something totally different than a selectBooleanCheckbox. – Kukeltje Feb 13 '18 at 21:48