Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 847
roel Avatar asked Jan 02 '12 14:01

roel


People also ask

How to pass a parameter to the server from A4J?

These parameters are passed to the server using a4j:actionparam tag. The name in a4j:actionparam is not important but should be set to something. The order is important. In other wordds, the value of the first parameters to the JavaScript function will be set into # {drink.bean} property in backing bean.

What is A4J jsfunction?

There is one more tag called a4j:jsFunction. This tags gives you a lot of power and flexibility. a4j:jsFunction lets you send an Ajax request from any user-defined JavaScript function. It can be a custom function or from any component-event as well.

Does a JavaScript function check parameter values?

A JavaScript function does not perform any checking on parameter values (arguments). Earlier in this tutorial, you learned that functions can have parameters: Function parameters are the names listed in the function definition. Function arguments are the real values passed to (and received by) the function.

What are function parameters and arguments in JavaScript?

Function parameters are the names listed in the function definition. Function arguments are the real values passed to (and received by) the function. JavaScript function definitions do not specify data types for parameters.


2 Answers

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

like image 87
Niks Avatar answered Nov 07 '22 15:11

Niks


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

like image 21
yatskevich Avatar answered Nov 07 '22 16:11

yatskevich