Sending parameter to a Controller

Gondim picture Gondim · Feb 24, 2011 · Viewed 7.2k times · Source

I got this:

<a4j:commandLink action="#{searchBean.someMethod}" reRender="search"><span><h:graphicImage value="/home/img/icons/red.gif" width="12" height="12" /> Street</span></a4j:commandLink>

And on my Bean, I got a method:

public void someMethod(String string){
  doStruff();
}

Is it possible to send a String as parameter to my method?

Answer

Eduard picture Eduard · Feb 24, 2011

You can send param with <f:param> like this

<a4j:commandLink action="#{searchBean.someMethod}" reRender="search">
     <span>
         <h:graphicImage value="/home/img/icons/red.gif" width="12" height="12" />Street
     </span>
   <f:param name="stringParam" value="someString" /> 
</a4j:commandLink>

and then get it in you method using ActionEvent

public void someMethod(ActionEvent actionEvent) {
    String s = (String) actionEvent.getComponent().getAttributes().get("stringParam");
}