gpt4 book ai didi

java - JSF:PanelGrid 不会呈现

转载 作者:行者123 更新时间:2023-11-29 05:52:04 26 4
gpt4 key购买 nike

我有一个带有 ajax 事件的复选框,在更改值时,该复选框将更改我的 bean 中的一个 boolean 值。此 ajax 事件还应呈现具有属性 rendered="#{!*the bean's boolean*}" 的 panelGrid。 .这意味着 panelGrid 应该在未选中时可见,在选中时可见。默认情况下, boolean 值将设置为 false(通过@PostConstruct)。

这是相应的代码片段:

<h:selectBooleanCheckbox id="useAddress" value="#{handleOrder.useAddress}">
<f:ajax event="change" execute="useAddress" render="outputAddress" />
</h:selectBooleanCheckbox>

<h:panelGrid id="outputAddress" rendered="#{!handleOrder.useAddress}" columns="2" width="468px">
(...)

此代码段被 <h:form /> 包围标签。我的getUseAddress()setUseAddress()将在 valuechange 时执行。

我的问题是,为什么我的 panelGrid 总是可见

最佳答案

不要用 f:ajax 指向具有 rendered 属性的元素,因为当这些元素不会被渲染时,f:ajax 是不可能的 找到它们。

f:ajax 必须指向生成的 HTML DOM 树中存在的元素,并且当某些 JSF 元素的 rendered 属性等于 false 该元素甚至不会出现在 HTML DOM 树中

把你的代码改成这样

<h:selectBooleanCheckbox id="useAddress" value="#{handleOrder.useAddress}">
<f:ajax event="change" render="outputAddressWrapper" />
</h:selectBooleanCheckbox>

不需要 execute="useAddress" 因为 execute 的默认值无论如何都是 @this

<h:panelGroup id="outputAddressWrapper">
<h:panelGrid id="outputAddress" rendered="#{!handleOrder.useAddress} columns="2" width="468px">
...

您说您的panelGrid 始终可见,您的 bean 的范围是什么?让它至少 @ViewScoped

关于java - JSF:PanelGrid 不会呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13518680/

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