带有selectBooleanCheckbox的JSF ReRender支持 [英] JSF ReRender support with selectBooleanCheckbox

查看:122
本文介绍了带有selectBooleanCheckbox的JSF ReRender支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSF页面,我想在该页面上有一个复选框,单击该复选框将在页面中添加/删除某些其他表单字段.这是我当前为复选框使用的(简化)代码:

I have a JSF page on which I want to have a checkbox that, when clicked, will add/remove certain other form fields from the page. Here is the (simplified) code I currently have for the checkbox:

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

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

Here is the code for the component I want to hide:

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

当前,单击复选框不会执行任何操作;那"selectOneMenu"将不会消失.我在做什么错了?

Currently, clicking the checkbox does nothing; that "selectOneMenu" will not go away. What am I doing wrong?

推荐答案

您需要将componentToReRender包装在以下任意一个中:

You need to wrap the componentToReRender in either:

<h:panelGroup id="componentToReRenderWrapper">

<a4j:outputPanel id="componentToReRenderWrapper">

因此,有效地,您将拥有:

So, effectively you will have:

<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的情况下删除该属性.

and change the reRender="componentToReRenderWrapper" in case you use panelGroup, or remove that attribute, in case you use outputPanel.

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

使用reRender的最常见问题是将其指向具有"rendered"属性的组件.注意,如果"rendered"条件返回false,JSF不会在浏览器DOM中标记应放置组件结果的位置.因此,在Ajax请求期间呈现组件之后,RichFaces将呈现的代码传递给客户端,但不会更新页面,因为更新的位置未知.您需要指向没有"rendered"属性的父组件之一.或者,您可以使用layout ="none"包装该组件.

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

这篇关于带有selectBooleanCheckbox的JSF ReRender支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆