gpt4 book ai didi

使用 selectBooleanCheckbox 支持 JSF ReRender

转载 作者:行者123 更新时间:2023-12-05 01:12:18 25 4
gpt4 key购买 nike

我有一个 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>

并更改 reRender="componentToReRenderWrapper"如果您使用 panelGroup ,或删除该属性,以防您使用 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" .

关于使用 selectBooleanCheckbox 支持 JSF ReRender,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2029462/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com