gpt4 book ai didi

ajax - f :ajax in ui:repeat renders h:outputText but fails to render/update h:inputText

转载 作者:行者123 更新时间:2023-12-01 23:59:23 24 4
gpt4 key购买 nike

我对 <f:ajax> 有疑问在 <h:inputText> 上里面<ui:repeat> .它成功呈现了 <h:outputText>使用新值,但不是 <h:inputText> (两者都绑定(bind)到相同的属性)。但是,如果我更改 <f:ajax>呈现 @form@all , 有用。但我显然不想/不需要渲染整个表单。

我使用的是 Mojarra 2.2.4。这是 index.xhtml

<h:form>
<table>
<ui:repeat var="line" value="#{myBean.lines}">
<tr>
<td>
<h:inputText value="#{line.number}">
<f:ajax event="change" execute="@this" render="desc1 desc2" listener="#{myBean.onChangeLineNumber(line)}"/>
</h:inputText>
</td>
<td>
<h:inputText id="desc1" value="#{line.desc}"/>
<h:outputText id="desc2" value="#{line.desc}"/>
</td>
</tr>
</ui:repeat>
</table>
</h:form>

这里是 @ViewScoped 的相关部分 bean :

public void onChangeLineNumber(Line line)
{
line.setDesc("Some new text " + System.currentTimeMillis());
}

这是怎么引起的,我该如何解决?

最佳答案

这是由 Mojarra 的状态管理错误引起的 <ui:repeat>这是固定的 issue 3215正如我的同事 Arjan Tijms 所报告的(实际上是针对一个完全不同的问题,修复恰好也恰好解决了您的问题)。该修复程序在 Mojarra 2.2.7 中可用.所以至少升级到那个版本应该可以。

否则,最好的办法是将其替换为 <h:dataTable> ,该组件专为基于集合呈现 HTML 表格的功能需求而设计。它还保存了一些 HTML 样板文件。

<h:form>
<h:dataTable value="#{myBean.lines}" var="line">
<h:column>
<h:inputText value="#{line.number}">
<f:ajax render="desc1 desc2" listener="#{myBean.onChangeLineNumber(line)}"/>
</h:inputText>
</h:column>
<h:column>
<h:inputText id="desc1" value="#{line.desc}"/>
<h:outputText id="desc2" value="#{line.desc}"/>
</h:column>
</h:dataTable>
</h:form>

(请注意,我从 event="change" 中删除了 execute="@this"<f:ajax>,因为它们已经是默认值,无需重复默认值)

关于ajax - f :ajax in ui:repeat renders h:outputText but fails to render/update h:inputText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22272271/

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