1

I'm using PrimeFaces' p:fieldset component and I want to control, from my bean, either or not it's collapsed. I expected the collpased property to do this job, but this is not working.

On the other hand, a "binding" seems to correctly mirror the component's state:

My Bean

@Named
@RequestScoped
public class TestBean {

    //with get/set
    private boolean collapsed;

    //with get/set
    private Fieldset fieldset;

 }

My page:

<h:form>
    <p:fieldset 
         id="togglebleFieldset"
         legend="Toggleable Fieldset"
         toggleable="true"
         binding="#{testBean.fieldset}"
         collapsed="#{testBean.collapsed}">

         fieldset content
         <p:ajax event="toggle" update="@form"/>      
    </p:fieldset>

    <h:outputText value="Value is never updated: #{testBean.collapsed}" />
    <br/><h:outputText value="Binding correctly reflects the state: #{testBean.fieldset.collapsed}" />
</h:form>

For reasons beyond the scope of this question, using the binding solution will be a little bit more complicated to me.

Why isn't #{testBean.collapsed} being update with the component's collapsed value?

(Using versions 6.0 and 6.2 of PrimeFaces)

bruno
  • 2,213
  • 1
  • 19
  • 31
  • My guess is that the `collapsed` attribute only defines *initial* state, and isn't able to keep track of *current* state. Instead of using a binding on it, try keeping track of the state with the `toggle` event. – Ayrton Feb 18 '19 at 16:50
  • @ayrton But what if I want to programmatically change the state, instead of just keep track of it? – bruno Feb 18 '19 at 17:47
  • Why don't you add a listener on the ajax tag and use that event to toggle the value? – Kukeltje Feb 19 '19 at 18:00
  • @Kukeltje Yes, I can synchronize the bean's state myself, but usually jsf take cares of that under-the-hoods. – bruno Feb 19 '19 at 20:25
  • 1
    No, not always (and in complex components, of which core-jsf sort of has none beside the 'plain' datatable, mostly never,). Oh... and check the bean scope. It is too short! You most likely reset it each time (boolean cannot be null); Duplicate: https://stackoverflow.com/questions/7031885/how-to-choose-the-right-bean-scope? – Kukeltje Feb 19 '19 at 20:32
  • @Kukeltje the page knows the fieldset state. What would justify an scope broader than Request? – bruno Feb 19 '19 at 21:44
  • That it gets lost/reset on a new request? Pr not submitted since the fieldSet is not an input. All just guessing here. Did you **try** viewscoped? – Kukeltje Feb 19 '19 at 22:41

0 Answers0