How to pass a parameter value to a4j:jsFunction

左心房为你撑大大i 提交于 2019-12-08 21:57:49

问题


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. Is it possible? It tried to do it with a4j:jsFunction and a4j:param but it does'nt work.

This is my code:

page 1:

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

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

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.

Is there a solution to my problem?


回答1:


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");. And then convert this param to int and utilize it further. That should work




回答2:


Try switching from actionListener to 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




回答3:


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:

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


来源:https://stackoverflow.com/questions/8702030/how-to-pass-a-parameter-value-to-a4jjsfunction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!