【问题标题】:f:ajax in ui:repeat renders h:outputText but fails to render/update h:inputTextf:ajax in ui:repeat 渲染 h:outputText 但无法渲染/更新 h:inputText
【发布时间】:2014-03-08 16:59:17
【问题描述】:

我在<h:inputText> 内部的<ui:repeat> 上遇到<f:ajax> 的问题。它成功地使用新值呈现 <h:outputText>,但不是 <h:inputText>(两者都绑定到同一个属性)。但是,如果我将<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());
}

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

【问题讨论】:

  • 请提供线路和myBean类的代码

标签: ajax jsf jsf-2.2 uirepeat


【解决方案1】:

这是由 Mojarra 的 &lt;ui:repeat&gt; 的状态管理中的错误引起的,正如我的同事 Arjan Tijms 所报告的那样,该错误已按照 issue 3215 进行了修复(实际上是针对一个完全不同的问题,该修复恰好可以解决您的问题出色地)。该修复程序在Mojarra 2.2.7 中可用。所以至少升级到那个版本就可以了。

否则,最好的办法是用&lt;h:dataTable&gt; 替换它,该组件的设计正是为了满足基于集合呈现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>

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

【讨论】:

  • 我们必须使用ui:repeat 而不是h:dataTable 是有原因的,但我不记得为什么了。谢谢你的回答!
猜你喜欢
  • 2011-05-07
  • 1970-01-01
  • 2011-04-02
  • 1970-01-01
  • 2011-10-14
  • 1970-01-01
  • 1970-01-01
  • 2014-01-24
  • 1970-01-01
相关资源
最近更新 更多