How to pass a parameter value to a4j:jsFunction

15,817

Solution 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

Solution 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

Solution 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;
}
Share:
15,817
roel
Author by

roel

Joe

Updated on June 09, 2022

Comments

  • roel
    roel almost 2 years

    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?