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.

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

As simple as that! Thanks! I was going in wrong way, was trying to change mypanelWidget.cfg properties
But just a curiosity, we cannot change it via javascript?
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: stackoverflow.com/questions/4421839/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.