微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

JSF ReRender支持selectBooleanCheckbox

我有一个JSF页面,我希望在其中有一个复选框,单击该复选框时,将从页面添加/删除某些其他表单字段.这是我目前为复选框提供的(简化)代码

<h:selectBooleanCheckBox title="showComponentToReRender" value="#{backingBean.showComponentToReRender}">
    <a4j:support event="onsubmit" reRender="componentToReRender" />
</h:selectBooleanCheckBox>

这是我要隐藏的组件的代码

<h:selectOneMenu id="componentToReRender" value="#{backingBean.value}" rendered="#{valuesList.rowCount>1 &amp;&amp; backingBean.showComponentToReRender}">
   <s:selectItems value="#{valuesList}" var="value"/>
</h:selectOneMenu>

目前,单击复选框不会执行任何操作“selectOneMenu”不会消失.我究竟做错了什么?

解决方法

您需要将componentToReRender包装在以下任一位置:

< h:panelGroup id =“componentToReRenderWrapper”>

要么

< a4j:outputPanel id =“componentToReRenderWrapper”>

所以,实际上你会有:

<h:panelGroup id="componentToReRenderWrapper">
    <h:selectOneMenu id="componentToReRender" value="#{backingBean.value}" rendered="#{valuesList.rowCount>1 &amp;&amp; backingBean.showComponentToReRender}">
       <s:selectItems value="#{valuesList}" var="value"/>
    </h:selectOneMenu>
</h:panelGroup>

如果使用panelGroup,则更改reRender =“componentToReRenderWrapper”,或者删除属性,以防使用outputPanel.

RichFaces文档中找到了确切的解释:

Most common problem with using reRender is pointing it to the component that has a “rendered” attribute. Note,that JSF does not mark the place in the browser DOM where the outcome of the component should be placed in case the “rendered” condition returns false. Therefore,after the component becomes rendered during the Ajax request,RichFaces delivers the rendered code to the client,but does not update a page,because the place for update is unkNown. You need to point to one of the parent components that has no “rendered” attribute. As an alternative,you can wrap the component with layout=”none” .

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐