Turn components on or off using the select flag

I have a component and I'm trying to disable the grid panel 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, clicking on the checkbox does not matter. The verification indicator does not even appear in the component of the checkbox and the value is bean: checked is not sent to the server. I also tried to use. A check indicator appeared, but the panel did not update.

How to use the update through the checkbox?

+6
source share
2 answers

Below is an example that I received:

 <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 by clicking the "Edit" button to check the box. Another problem is that if you do not display <h:panelGrid> , the identifier cannot be updated, so you want to move the rendered attribute to the components inside your <h:panelGrid> , but still update <h:panelGrid> .

+13
source

A slight deviation. The bean support field does not have to be logical. If you had bean support with fields:

 private List<SelectItem> myStringList; private String myString; 

then you initialize myStringList like this before loading the form:

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

then you can 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> 
0
source

Source: https://habr.com/ru/post/893231/


All Articles