1

I'm working on project that uses Primefaces 3.5 (yeah, it is a quite old version). What I wanted to implement is a function in Javascript, that will change attribute of Primefaces element. Is it possible to do?

What I have is a panel defined as:

<p:panel id="mypanel" widgetVar="mypanelWidget" header="A title here" toggleable="true" toggleOrientation="vertical" collapsed="true">

And my idea is to change collapsed="true" to collapsed="false" with Javascript.

This necessity surged because of an ajax call that updates panel, and when it is updated, it appears as collapsed. Doing mypanelWidget.expand() on callback is not a good idea as my page becomes very animated.

andriy
  • 4,074
  • 9
  • 44
  • 71

1 Answers1

2

Two options:

  1. Simply use EL in collapsed attribute to check some model state instead of specifying a hardcoded true.

    <p:panel ... collapsed="#{not bean.ajaxMethodCalled}">
    

    Whereby you make sure that isAjaxMethodCalled() returns true if the ajax method of interest was called. It doesn't necessarily need to be a boolean property, it can be anything, including checking the HTTP request parameter map, as long as it evaluates to the desired boolean result.

  2. Don't update the panel itself during ajax call. Instead, update its contents.

    <p:panel ...>
        <h:panelGroup layout="block" id="panelContents">
            ...
            <p:ajax update="panelContents" />
            ...
        </h:panelGroup>
    </p:panel>
    

    This way the state of panel's HTML representation in the HTML DOM tree remains intact.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • As simple as that! Thanks! I was going in wrong way, was trying to change `mypanelWidget.cfg` properties – andriy Sep 22 '15 at 08:08
  • But just a curiosity, we cannot change it via javascript? – andriy Sep 22 '15 at 08:15
  • 1
    It's possible. It's only going to be clumsy as you're basically taking over and duplicating JSF's responsibilities/capabilities. It appears that you're new to JSF, so here's some food for read: http://stackoverflow.com/questions/4421839/what-is-the-need-of-jsf-when-ui-can-be-achieved-from-css-html-javascript-jquery/ – BalusC Sep 22 '15 at 08:16