开发者

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?


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"/>


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜