2011-02-24 3 views
2

je me suis ceci:Envoi paramètre à un contrôleur

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

Et sur mon Bean, je me suis une méthode:

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

Est-il possible d'envoyer une chaîne en tant que paramètre à ma méthode?

Répondre

3

Vous pouvez envoyer avec <f:param> comme param cette

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

puis l'obtenir en vous utilisant la méthode ActionEvent

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

Vous pouvez aussi le faire avec a4j: actionparam. Dans le haricot, vous n'avez besoin que d'un getter/setter, vous n'avez pas besoin de récupérer vous-même le param. a4j: actionparam fait l'assignation automatiquement.

Questions connexes