2

I'm using primefaces and working on a complex form. I need to hide a part of the form, depending on the value of a checkbox

    <p:selectBooleanButton id="input1" .... />
<p:inputText id="input2" />


<!-- the boolean checkbox -->
<p:selectBooleanCheckbox id="checkBox1" value="#{bbean.someBoolValue}" >
    <p:ajax event="change" update=":#{p:component('someParentcComponentsId')}" />
</p:selectBooleanCheckbox>

<!-- some input fields here. These will be rendered depending checkBox1 value -->
<p:panel rendered="#{bbean.someBoolValue}" id="hiddingPanel">   
    <h:panelGrid columns="2" >

        <p:inputText id="input3" />
    </h:panelGrid>
</p:panel>

So far, I've made that work, so when checkBox1 is clicked, hiddingPanel is getting shown or hidden. But there's a catch: the values of every input in that form ( e.g. input1, input2 ) are lost, since the 'change' ajax event is not submitting their values.

How could I make sure that all input values are submitted before updating the form ?

yannicuLar
  • 3,083
  • 3
  • 32
  • 50

1 Answers1

7

Just make sure that you update only the section which really needs to be updated.

<p:selectBooleanCheckbox id="checkBox1" value="#{bbean.someBoolValue}" >
    <p:ajax event="change" update="hiddingPanel" />
</p:selectBooleanCheckbox>

<!-- some input fields here. These will be rendered depending checkBox1 value -->
<p:panel id="hiddingPanel">   
    <h:panelGrid columns="2" rendered="#{bbean.someBoolValue}">

        <p:inputText id="input3" />
    </h:panelGrid>
</p:panel>

Note that I moved rendered to its immediate child, for the reasons explained here: Why do I need to nest a component with rendered="#{some}" in another component when I want to ajax-update it?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you BalusC. for your answer. So there is no way to (partially) submit the form ? If that's the case, then I should indeed update a part of the form, just to avoid losing unsubmitted changes. – yannicuLar Nov 19 '13 at 13:18
  • 1
    Uh, I just answered exactly how to acheive that? Or do you mean to partially process a form? If so, you can control that with `process` attribute, but this defaults in case of `` already to `@this`. – BalusC Nov 19 '13 at 13:24
  • What I really wanted was to submit the whole form. I tried 'process="@form"' and everything seems to work fine. I think this is exactly what I needed. Thanx again – yannicuLar Nov 19 '13 at 13:31
  • Impressed by your solution..... i have wasted 4 hours to solve the problem. thanks @BalusC – Irfan Nasim Apr 17 '15 at 10:23