动态更改 JSF 组件的可见性

发布于 2024-09-08 20:08:58 字数 965 浏览 3 评论 0原文

我的要求是这样的:我有一个文本输入,每当发生值更改事件时,都必须填充一个多选列表框。如果没有找到匹配的记录,则必须出现文本输入而不是选择多个列表框。

    <h:column>
<h:selectManyListbox size="3" value="#{hostInfoBean.gateKeeperendPointReference}" rendered="#{hostInfoBean.selectManyRendered}"                             id="gateKeeperendPointReference">
<f:selectItems value="#{hostInfoBean.gateKeeperendPointReferenceItems}" />
</h:selectManyListbox>
<h:inputText id="gateKeeperendPointReferenceText" size="30" rendered="#{!hostInfoBean.selectManyRendered}">
</h:inputText>
</h:column>

另外,我使用 a4j 作为值更改侦听器,

<a4j:support event="onchange"                   reRender="hostInfo:gateKeeperendPointReference" focus="GFacPath"
                    ajaxSingle="true" />

“selectManyRendered”是我在 JAVA bean 中确定的布尔值。该程序仅适用于布尔变量的默认值。如果布尔值在运行时发生更改,则 selectManyListbox 和 inputText 的可见性之间的切换将不起作用。请帮助解决这个问题。我错过了什么吗?

问候, 苏雷什

My requirement is like this: I am having a text input and whenever a value change event occurs, a select many list box has to be populated. If there is no matching records found, then a text input has to appear instead of a select many list box.

    <h:column>
<h:selectManyListbox size="3" value="#{hostInfoBean.gateKeeperendPointReference}" rendered="#{hostInfoBean.selectManyRendered}"                             id="gateKeeperendPointReference">
<f:selectItems value="#{hostInfoBean.gateKeeperendPointReferenceItems}" />
</h:selectManyListbox>
<h:inputText id="gateKeeperendPointReferenceText" size="30" rendered="#{!hostInfoBean.selectManyRendered}">
</h:inputText>
</h:column>

Also I am using a4j for the value change listener,

<a4j:support event="onchange"                   reRender="hostInfo:gateKeeperendPointReference" focus="GFacPath"
                    ajaxSingle="true" />

'selectManyRendered' is a boolean value which I am determining in the JAVA bean. The program works only for the default value of the boolean variable. If the boolean value is changed during runtime, then the toggle between the visibility of selectManyListbox and inputText is not working. Please help to fix this. Am i missing something?

regards,
Suresh

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

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

发布评论

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

评论(1

月依秋水 2024-09-15 20:08:58

如果“rendered”属性解析为 false,则该组件不在您的树中,并且无法作为“rerender”目标找到。当您有条件渲染的组件时,您希望将它们包装在始终可用作目标的组件中,如下所示:

<h:inputText value="#{myBean.text}" >
  <a4j:support event="onkeyup" reRender="listZone" ajaxSingle="true" />
</h:inputText>
<h:panelGroup id="listZone">
  <h:selectManyListbox value="#{myBean.list}" rendered="#{myBean.renderList}" >
    <f:selectItems value="#{myBean.listItems}" />
  </h:selectManyListbox>
  <h:inputText size="30" rendered="#{!myBean.renderList}/>
<h:panelGroup id="listZone">

If the "rendered" attribute resolves to false, then the component isn't in your tree and can't be found as a "rerender" target. When you have components that are rendered conditionally you want to wrap them in a component that is always available as a target, like so:

<h:inputText value="#{myBean.text}" >
  <a4j:support event="onkeyup" reRender="listZone" ajaxSingle="true" />
</h:inputText>
<h:panelGroup id="listZone">
  <h:selectManyListbox value="#{myBean.list}" rendered="#{myBean.renderList}" >
    <f:selectItems value="#{myBean.listItems}" />
  </h:selectManyListbox>
  <h:inputText size="30" rendered="#{!myBean.renderList}/>
<h:panelGroup id="listZone">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文