Skip to content

Mis en ligne par admin - 20 janvier 2014 - Web Applications

Simple Primefaces remoteCommand usage

In order to call a managed bean function with parameters sent from Javascript, here is a 3 steps short tutorial for PrimeFaces.

1. Call a javascript function (jsFunction1) with the following structure style (array of name/values)

jsFunction1([{name:'param1', value:jsVar1}, 
{name:'param2', value:jsVar2}, {name: 'param3',value: jsVar3}]);

2. Create a remoteCommand (used to map javascript call to managed bean action). The name should be the same as the javascript function.

<p:remoteCommand name="jsFunction1"
        action="#{anyBean.action}" update="xxx">
      </p:remoteCommand>

3. In the managed bean (anyBean), you may retrieve the parameters as shown below:

public void action() {
    Map<String, String> params = FacesContext.getCurrentInstance()
        .getExternalContext().getRequestParameterMap();
    param1 =  params.get("param1"));
}

Not much complicated !

Articles similaires

Les articles suivants abordent des thèmes communs.

Commentaires

Partagez vos remarques.

Il n'y a pas de commentaires pour cet article.

Add a Comment

Fill in the form and submit.