【问题标题】:How to pass a parameter value to a4j:jsFunction如何将参数值传递给 a4j:jsFunction
【发布时间】:2012-01-31 21:19:21
【问题描述】:

在我的页面上,我有一个按钮,可以在弹出窗口中打开项目列表。当我在列表中选择一个项目时,我想将项目的 id 传递给我的第一页的 backingbean。可能吗?它试图用a4j:jsFunctiona4j:param 来做到这一点,但它不起作用。

这是我的代码:

第 1 页:

<a4j:jsFunction name="renderGuarantor" render="guarantor" actionListener="#{prospectDetail.setNewGuarantor}">
  <a4j:param name="param1" assignTo="#{prospectDetail.newGuarantorId}" />  
</a4j:jsFunction>

弹出页面:

<h:outputLink value="" onclick="window.opener.renderGuarantor(#{applicant.deposit_id});window.close();">
  <h:graphicImage style="padding:0 1px; border:0"  value="${path.staticRootUrl}images/confirm.gif"  alt="${msg.applicantslist_select}" title="${msg.applicantslist_select}"/>
</h:outputLink>

这是第一页的支持 bean 代码

private Integer newGuarantorId;
public void setNewGuarantor()  {
    guarantor = newGuarantorId;
}

public Integer getNewGuarantorId() {
    return newGuarantorId;
}

public void setNewGuarantorId(Integer newGuarantorId) {
    this.newGuarantorId = newGuarantorId;
}

在弹出窗口中选择时,我的 backingbean 中的方法被调用,但 newGuarantorId 为 null 并且永远不会调用 setNewGuarantorId

我的问题有解决方案吗?

【问题讨论】:

  • 您确定#{applicant.deposit_id} 在新窗口中不为空吗?
  • 是的,它填写了正确的 id。
  • 嗯..这很奇怪,看起来没什么问题..不是您的问题的答案,但请尝试此解决方法 - 不要将值分配给 guarantorId,而是将参数保留为 &lt;a4j:param name="param1"/&gt; 并在actionListener 方法将此 param1 从请求中检索为 String param1 = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("param1");。然后将此参数转换为int 并进一步利用它。那应该可以。
  • 太棒了! :) 把它作为答案放在下面。如果它是您问题的答案,请标记它

标签: ajax jsf jsf-2 richfaces ajax4jsf


【解决方案1】:

嗯..这很奇怪,看起来没什么问题..不是您的问题的答案,但请尝试此解决方法 - 不要将值分配给 guarantorId,而是将参数保留为 &lt;a4j:param name="param1"/&gt; 并在 actionListener 方法中检索此参数 1来自String param1 = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().‌​get("param1"); 的请求。 然后将此参数转换为 int 并进一步利用它。应该可以的

【讨论】:

    【解决方案2】:

    尝试从actionListener切换到action

    <a4j:jsFunction name="renderGuarantor" render="guarantor" action="#{prospectDetail.setNewGuarantor}">
      <a4j:param name="param1" assignTo="#{prospectDetail.newGuarantorId}"/>  
    </a4j:jsFunction>
    

    这里推荐阅读主题:a4j:jsFunction

    【讨论】:

      【解决方案3】:

      我想你可以试试这个:

      <a4j:jsFunction name="renderGuarantor" render="guarantor" 
                      actionListener="#{prospectDetail.setNewGuarantor(prospectDetail.newGuarantorId)}" />
      

      在您的托管 bean 中,定义 setNewGuarantor 方法如下:

      public void setNewGuarantor(int newGuarantorId)  {
         guarantor = newGuarantorId;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-05-05
        • 2010-09-25
        • 2020-08-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-26
        • 2011-06-13
        相关资源
        最近更新 更多