【问题标题】:How to pass a parameter in p:ajax when we used it with p:inputText?当我们将它与 p:inputText 一起使用时,如何在 p:ajax 中传递参数?
【发布时间】:2014-12-22 07:14:15
【问题描述】:

我需要在我的 p:ajax 方法中传递一个参数。有一个<p:inputText>,当我完成输入输入框时,必须更新我的 p:ajax 方法。但我无法在我的方法中发送参数。

我的jsf页面是:

<h:outputText value="#{msg['elicense.contractorFormRenewal.personal.registrationNo']}"/>
<p:inputText id="registrationNo" value="#{renewalContractorBean.registrationNo}"  required="false" label="Registration No">
    <p:ajaxlistener="#{renewalContractorBean.readLicenseDetailsById(renewalContractorBean.registrationNo)}/>
</p:inputText>

我在bean中的方法是

public void readLicenseDetailsById(String id) {
    FirmOrCompany firmOrCompany = contractorRenewableService.readLicenseDetailsById(id);
    this.setLicenseName(firmOrCompany.getLicensePersonName());
    this.setClassofLicense(firmOrCompany.getLicenseAppliedFor());
}

【问题讨论】:

  • 没有&lt;p:ajaxlistener&gt;这样的东西吗?
  • 为什么要在页面中传递值,当它存在于支持 bean 中时,以及需要它的方法?为什么不能在不传入的情况下使用 readLicenseDetailsById 中的实例变量?

标签: ajax jsf jsf-2 primefaces


【解决方案1】:

没有&lt;p:ajaxListener&gt;,不知道你是否漏掉了代码或问题。

考虑到你在问题中犯了一个错误,你的方法应该可以正常工作,你只是忘记在&lt;p:ajax&gt;中设置event=blur,所以一旦你离开inputTextBox它就会被调用(意味着用户已经完成输入)

  <p:inputText id="registrationNo" value="#{renewalContractorBean.registrationNo}" required="false" label="Registration No">
       <p:ajax event="blur" listener="#{renewalContractorBean.readLicenseDetailsById()}/>
  </p:inputText>

检查如果你想更新另一个组件,基于你在你的bean中所做的改变,你必须在&lt;p:ajax&gt;&lt;p:ajax event="blur" update"IdOfTheComponent" ....&gt;中指定那个组件的id

此外,您不必将 bean 中已经存在的属性作为参数传递,您可以在 bean 中获取它。

最后,在renewalContractorBean

public void readLicenseDetailsById()
{
  String id = this.registrationNo;
  FirmOrCompany firmOrCompany= contractorRenewableService.readLicenseDetailsById(id);
  this.setLicenseName(firmOrCompany.getLicensePersonName());
  this.setClassofLicense(firmOrCompany.getLicenseAppliedFor());

}

【讨论】:

    【解决方案2】:

    您好,您尝试过update="tableid" 吗?当我从 p:dataTable 中的列表中删除时,JSF 可以更新这个 dataTable 我希望这会有所帮助。 这是我更新 p:datatable 的代码

    <p:dataTable id="tbl" value="#{borrowerBean.borrowers}" var="bor">
                <p:column>
                    <f:facet name="header">
                        <h:outputLabel>ID: </h:outputLabel>
                    </f:facet>
                    <h:outputLabel value="#{bor.id}"/>
                </p:column>
    .
    .
    .
        <p:commandButton value="Delete" action="#{user.deleteBorrower(bor.id)}" update="tbl"/>
                </p:column>
    </p:dataTable>
    

    【讨论】:

      猜你喜欢
      • 2018-11-25
      • 2011-01-19
      • 1970-01-01
      • 2018-08-24
      • 2015-01-19
      • 2022-01-09
      • 1970-01-01
      • 1970-01-01
      • 2012-10-14
      相关资源
      最近更新 更多