F:阿贾克斯在UI:重复渲染H:的outputText但没有渲染/更新h:inputText的UI、阿贾克斯、inputText、outputText

2023-09-11 22:30:56 作者:怀念你的拥抱,

我有一个℃的问题; F:AJAX> < H:inputText的> < UI:重复> 。它成功地呈现一个< H:的outputText> 新的价值,而不是< H:inputText的> (两者都绑定到相同的属性)。不过,如果我改变了< F:AJAX> 渲染 @form @所有,它的工作原理。但我显然不希望/需要渲染整个表单。

I have a problem with <f:ajax> on a <h:inputText> inside <ui:repeat>. It successfully renders a <h:outputText> with the new value, but not a <h:inputText> (both are bound to the same property). However, if I change the <f:ajax> to render @form or @all, it works. But I obviously don't want/need to render the whole form.

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

I'm using Mojarra 2.2.4. Here's the 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的相关位:

And here's the relevant bit of the @ViewScoped bean:

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

这是怎么造成的,我该怎么解决呢?

How is this caused and how can I solve it?

推荐答案

这是由于在Mojarra的&LT状态管理的错误; UI:重复&GT; 这是固定的按照问题3215 所报告的我的同胞阿尔扬Tijms(实际上是一个完全不同的问题,修复恰好完全解决你的问题以及)。解决方法是在 Mojarra 2.2.7 可用。因此,升级到至少那个版本应该这样做。

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). The fix is available in Mojarra 2.2.7. So upgrading to at least that version should do it.

否则,你最好的选择是由&LT来替代它; H:dataTable的&GT; ,这是专为呈现HTML表格完全相同的功能需求的基于组件的上的集合。这也节省了一些HTML样板。

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. It also saves some HTML boilerplate.

<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; 因为那些是默认已经,没有必要重复默认值)的

(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)