简体   繁体   English

如何将参数值传递给a4j:jsFunction

[英]How to pass a parameter value to a4j:jsFunction

On my page I have a button that opens a list of items in a popup. 在我的页面上,我有一个按钮,用于打开弹出窗口中的项目列表。 When I select 1 item in the list, I want to pass the id of the item to the backingbean of my first page. 当我在列表中选择1项时,我想将项目的ID传递给我的第一页的后台。 Is it possible? 可能吗? It tried to do it with a4j:jsFunction and a4j:param but it does'nt work. 它尝试用a4j:jsFunctiona4j:param a4j:jsFunction ,但它不起作用。

This is my code: 这是我的代码:

page 1: 第1页:

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

popuppage: popuppage:

<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>

And this is the backing bean code for the first page 这是第一页的支持bean代码

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

public Integer getNewGuarantorId() {
    return newGuarantorId;
}

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

When selecting in the popup the method in my backingbean is called, but newGuarantorId is null and setNewGuarantorId is never called. 在弹出窗口中选择时,调用我的backingbean中的方法,但newGuarantorId为null, setNewGuarantorId永远不会调用setNewGuarantorId

Is there a solution to my problem? 我的问题有解决方案吗?

Hmm.. thats strange, nothing looks wrong..Not an answer to your question but try this workaround - instead of assigning the value to guarantorId, keep the param as <a4j:param name="param1"/> and in the actionListener method retrieve this param1 from the request as String param1 = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().‌​get("param1"); 嗯...这很奇怪,没什么看错。没有回答你的问题但尝试这个解决方法 - 而不是将值赋值给guarantorId,保持param为<a4j:param name="param1"/>并在actionListener方法中从请求中检索此param1为String param1 = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().‌​get("param1"); . And then convert this param to int and utilize it further. 然后将此参数转换为int并进一步利用它。 That should work 这应该工作

Try switching from actionListener to action : 尝试从actionListener切换到action

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

Here is recommended reading on the topic: a4j:jsFunction 建议阅读以下主题: a4j:jsFunction

I think you can try this: 我想你可以试试这个:

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

And in your Managed bean, define the setNewGuarantor method as following: 在您的Managed bean中,定义setNewGuarantor方法如下:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM