简体   繁体   English

f:ui中的ajax:重复渲染h:outputText但无法渲染/更新h:inputText

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

I have a problem with <f:ajax> on a <h:inputText> inside <ui:repeat> . 我在<ui:repeat>里面的<h:inputText>上遇到了<f:ajax>的问题。 It successfully renders a <h:outputText> with the new value, but not a <h:inputText> (both are bound to the same property). 它成功地使用新值呈现<h:outputText> ,但不是<h:inputText> (两者都绑定到同一属性)。 However, if I change the <f:ajax> to render @form or @all , it works. 但是,如果我将<f:ajax>更改为渲染@form@all ,则可以正常工作。 But I obviously don't want/need to render the whole form. 但我显然不希望/需要呈现整个表单。

I'm using Mojarra 2.2.4. 我正在使用Mojarra 2.2.4。 Here's the index.xhtml 这是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>

And here's the relevant bit of the @ViewScoped bean: 这是@ViewScoped bean的相关位:

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

How is this caused and how can I solve it? 这是怎么造成的,我该如何解决?

This is caused by a bug in state management of Mojarra's <ui:repeat> which is fixed as per issue 3215 as reported by my fellow Arjan Tijms (actually for a completely different problem, the fix just happens to solve exactly your problem as well). 这是由Mojarra的<ui:repeat>状态管理中的一个错误造成的,根据我的同事Arjan Tijms报告的问题3215 (实际上对于一个完全不同的问题,修复恰好解决了你的问题) 。 The fix is available in Mojarra 2.2.7 . Mojarra 2.2.7中提供了此修复程序。 So upgrading to at least that version should do it. 所以升级到至少那个版本应该这样做。

Otherwise, your best bet is to replace it by a <h:dataTable> , the component which is designed for exactly the functional requirement of rendering a HTML table based on a collection. 否则,最好的办法是用<h:dataTable>替换它,该组件的设计完全符合基于集合呈现HTML表的功能要求。 It also saves some HTML boilerplate. 它还节省了一些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>

(note that I removed event="change" and execute="@this" from the <f:ajax> as those are the defaults already, there's no need to repeat the defaults) (注意我从<f:ajax>删除了event="change"execute="@this" ,因为这些是默认值,不需要重复默认值)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 重新渲染后,JSF ui:repeat和f:ajax为h:inputText提供错误的值 - JSF ui:repeat and f:ajax giving wrong value for h:inputText after rerender h:与f:ajax和ui:repeat一起使用时,不会调用commandLink actionlistener - h:commandLink actionlistener is not invoked when used with f:ajax and ui:repeat 行为异常 <f:ajax> 内 <h:form> 内 <ui:repeat> - Strange behavior with <f:ajax> inside <h:form> inside <ui:repeat> h:form中具有h:selectOneMenu,h:outputText和f:ajax的执行顺序 - execution-order in h:form with h:selectOneMenu, h:outputText and f:ajax 无法通过(Primefaces)p:ajax调用更新h:outputText标记 - Fail to update h:outputText tag with (Primefaces) p:ajax call h:inputText inside ui:repeater 在 ajax 更新后显示错误值 - h:inputText inside ui:repeater displays wrong value after an ajax update 取决于h:selectOneRadio选择,通过ajax有条件地渲染h:selectOneMenu和h:inputText - Conditionally render h:selectOneMenu and h:inputText by ajax depending on h:selectOneRadio selection 如何在h:inputText中将参数传递给f:ajax? f:param不起作用 - How to pass parameter to f:ajax in h:inputText? f:param does not work 为什么 p:ajax 不会在 primefaces 5 和 JSF2 中更新我的 h:outputText? - Why p:ajax doesn´t update my h:outputText in primefaces 5 and JSF2? f:ajax不会更新ui:repeat - f:ajax does not update ui:repeat
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM