NRaf
NRaf

Reputation: 7549

Seam/RichFaces: Rendering based on result of a JavaScript function or variable

I have a RichFaces component that I want to render after an Ajax call which sets a JavaScript variable to either true or false.

When the variable is false, I don't want the panel to render. Is there any way to input the result of this variable (or any JS function call) in the rendered attribute of a component?

Upvotes: 0

Views: 2303

Answers (3)

gorlok
gorlok

Reputation: 1155

Option 1: You can show/hide using JavaScript/jQuery from oncomplete attribute on ajax request.

Option 2 (better): you change a boolean property value in backend action's method, and use its value in rendered attribute.

Upvotes: 1

Max Katz
Max Katz

Reputation: 1582

RichFaces reRender can take an EL expression:

reRender="#{bean.componentsToUpdate}"

So, another option, you can decide in runtime (based on input) whether to render a particular component.

Upvotes: 0

zinan.yumak
zinan.yumak

Reputation: 1590

Richfaces renders components on the server side. So you have to pass your parameter to server side. There are some ways to achieve this. Create a hidden input on the page and link it to a flag in your bean. Something like,

class YourBean {

      private boolean visible = false;

      //getter,setter

}

On the page,

<h:selectBooleanCheckbox id="hiddeninput" style="visibility:hidden" 
     value="#{yourBean.visible}"/> 
<rich:component id="compid" rendered="#{yourBean.visible}" />

<a:commandButton onclick="document.getElementById('hiddeninput').checked=true" 
     reRender="compid"/>

Or create two methods which sets flag to true or false.

class YourBean {

      private boolean visible = false;

      public void makeInvisible() {
           visible = false;
      }

      public void makeVisible() {
           visible = true;
      }

}

On the page,

<rich:component id="compid" rendered="#{yourBean.visible}" />

<a:commandButton action="#{yourBean.makeInvisible()}" reRender="compid"/>

Upvotes: 2

Related Questions