【问题标题】:p:inputText element empty if it's the target of ajax update attributep:inputText 元素为空,如果它是 ajax 更新属性的目标
【发布时间】:2018-04-06 11:20:15
【问题描述】:

我有下面的代码。我删除了构面和类似的标签,使其更具可读性。我高度怀疑他们是问题所在。我对所有标签都使用 Primefaces 6.1,除了表单标签是 Omnifaces。

<h:form id="form">
    <p:dataTable id="table" value="#{data.rows}" var="row" rowIndexVar="index">
        <p:column id="ajaxColumn" rendered="#{true}">
            <p:inputText id="ajaxValue" value="#{row.ajaxValue}">
                <p:ajax event="blur" process="@this" update="@this form-table-#{index}-targetColumn" listener="#{bean.ajaxMethod(index)}"/>
            </p:inputText>
        <p:column>
        <p:column id="targetColumn"rendered="#{true}">
            <p:inputText id="targetValue" value="#{row.targetValue}"/>
        </p:column>
    </p:dataTable>
</h:form>

在 'ajaxValue' inputText 取消选择导致模糊事件之后,我想用新值更新 'targetValue' inputText。 ajax 调用应该将 'ajaxValue' 中的值发送到后端,并相应地在 bean 中设置 'targetValue'。之后,“targetValue”应该更新为新值。

我的问题是,当我将“form-table-#{index}-targetColumn”添加到 ajax 标记的更新属性时,“targetValue”从一开始就保持为空。它在前端没有任何价值。如果我改为添加“form-table-0-targetColumn”,则只有第一个“targetValue”没有值。

在调试时查看 getter 调用,无论我是否具有更新属性,它们的行为都是相同的。

有什么想法吗?

编辑:澄清。 ID 中的分隔符是“-”,而不是“:”,我相信它们通常是这样的。

【问题讨论】:

  • 那你为什么不写 : 而不是 - ?我是一个数据表,你不能使用索引来更新行。如果你想在同一行更新,我相信你应该使用update="targetColumn"
  • 您是否在开发模式下运行您的应用程序?
  • update="targetColumn" 工作,谢谢。很高兴知道。至于“:”与“-”,似乎是公司的决定。稍后我会问他们原因。

标签: ajax jsf primefaces


【解决方案1】:

在数据表中,您不能使用索引来更新行。如果要更新同一行中的某些元素,则应使用 update="targetColumn"。

(在某个地方一定有这个副本,但我找不到它,直到我找到它,我会在这里留下这个答案

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-30
    • 2015-06-02
    • 2013-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多