<h:inputText>不更新

<h:inputText> does not update

我有一个带有表单和输入文本的页面,它表示一个 bean 的值。在页面底部,我有一个导航按钮可以转到下一个条目:

<h:form id="customerData">
...
    <h:outputText value="#{customeredit.customer.name}" />
    <br />
    <h:inputText size="60" id="name" value="#{customeredit.customer.name}" />
...
</h:form>

<p:commandButton value="Next customer" action="customers" ajax="false" id="nextCustomer">
    <f:param name="linkageAreaId" value="#{customeredit.nextCustomer.id}" />
</p:commandButton>

如果我单击该按钮,页面将重新加载,一个新的客户对象将在后台加载,并且除了 inputText 之外的所有条目都会更新。 outputText 发生变化,但 inputText 始终保持初始化时获得的值。我还检查了吸气剂,吸气剂的值 return 随着新客户的变化而变化,但 inputText 中显示的值始终保持不变。

如果您嵌套表单(即 HTML 中的 illegal),则可能会发生这种情况,因此输入和按钮最终都以相同的形式结束。然后该按钮也会提交输入字段。在任何情况下,您都不应该使用 <p:commandButton> 进行页面到页面的导航。请改用 <p:button>

<p:button value="Next customer" outcome="customers" id="nextCustomer">
    <f:param name="linkageAreaId" value="#{customeredit.nextCustomer.id}" />
</p:button>

别忘了修复嵌套表单问题。

另请参阅:

  • How to navigate in JSF? How to make URL reflect current page (and not previous one)
  • Difference between h:button and h:commandButton