JSF ReRender 支持 selectBooleanCheckbox

发布于 2024-08-17 05:22:45 字数 684 浏览 2 评论 0原文

我有一个 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”不会消失。我做错了什么?

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 && backingBean.showComponentToReRender}">
   <s:selectItems value="#{valuesList}" var="value"/>
</h:selectOneMenu>

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

禾厶谷欠 2024-08-24 05:22:45

您需要将 componentToReRender 包装在:

中因此

,实际上,您将拥有:

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

如果您使用 panelGroup,则更改 reRender="componentToReRenderWrapper",或者删除该属性,如果您使用 <代码>输出面板。

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

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

You need to wrap the componentToReRender in either:

<h:panelGroup id="componentToReRenderWrapper">

or

<a4j:outputPanel id="componentToReRenderWrapper">

So, effectively you will have:

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

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

Found the exact explanation in the RichFaces docs:

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

七七 2024-08-24 05:22:45

不要忘记在 a4j:outputPanel 上设置 ajaxRendered="true"

Don't forget to set ajaxRendered="true" on the a4j:outputPanel

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文