【问题标题】:p:ajax update not working after clicking commandlinkp:ajax 更新在单击命令链接后不起作用
【发布时间】:2013-07-23 14:24:51
【问题描述】:

我有一个添加来自客户的订单的 jsf 页面。
一切正常,除非我单击 commandLink 以显示 p:dialog 以添加新客户端“reste”输入文本上的更新停止工作(即使我关闭 p:dialog 而不添加新客户端):

客户名单:

<strong>Client :</strong><
<p:autoComplete
   id="client"
   value="#{venteSolaireBean.client}"
   completeMethod="#{venteSolaireBean.autocompleteClient}"
   var="item"
   itemLabel="#{item.nom} #{item.prenom}"
   itemValue="#{item}"
   converter="#{venteSolaireBean.clientConverter}"
   dropdown="true" 
   scrollHeight="200" >
</p:autoComplete>

链接到 p:dialog 以添加新的 Cleint:

<p:commandLink onclick="dlgClient.show()" immediate="true">
   <img src="images-main/add-icon.gif" border="0" alt="Add Client" class="img-action"/>
</p:commandLink>

三个具有 ajax 行为的 p:inputtext 项:

<strong>Montant :</strong>
<p:inputText value="#{venteSolaireBean.venteSolaire.montant}">
    <p:ajax event="keyup" update="reste" listener="#{venteSolaireBean.calcul}" />
</p:inputText>

<strong>Avance :</strong></td>
<p:inputText value="#{venteSolaireBean.venteSolaire.avance}">
    <p:ajax event="keyup" update="reste" listener="#{venteSolaireBean.calcul}" />
</p:inputText>

<strong>Reste :</strong></td>
<p:inputText id="reste" value="#{venteSolaireBean.venteSolaire.reste}">
</p:inputText>

与监听器一起执行的 venteSolaireBean.calcul 函数:

public void calcul() {
    venteSolaire.setReste(venteSolaire.getMontant() - venteSolaire.getAvance());
}

我通过记录 calcul() 函数进行了检查,我确定它已被调用并且给 setReste() 的值是正确的。

我不明白为什么 inputtext 没有更新。
请帮忙。

【问题讨论】:

  • 你为什么使用immediate="true"
  • 跳过验证第一个表单,因为我将两个表单用于“客户订单”和“添加客户”对话框的订单
  • 但是您没有使用用于显示对话框的按钮提交任何内容。您实际上不需要p:commandButton,它也可以是普通的button,因为您没有使用此按钮执行任何特定于 JSF 的操作。
  • 哦是的,最好的方法是最简单的,我真的专注于jsf,我忘记了简单的html,谢谢你的提示。写一个答案,我会接受的,

标签: ajax jsf-2 primefaces commandlink


【解决方案1】:

我认为验证存在一些问题。由于immediate=true 经常导致此类问题,并且您没有在按钮上使用任何primefaces 功能来显示对话框,因此您应该将p:commandButton 替换为纯HTML button 以显示“添加客户端”对话框。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多