Is it possible to return a value using Remotecommand?

Asked

Viewed 72 times

-2

I wonder if in the same way it is possible to pass parameters to a function of a "remoteCommand" if it is possible to receive the return? Just like the example:

Xhtml:<p:remoteCommand name="myRemoteCommand" actionListener="#{testBean.testRemote }" />

Javasctript: myRemoteCommand([{name:"id", 1}]);

Bean:

public void testRemote()
    {
        String[] id = JSFUtil.getRequestParameterMap().get("id");
        System.out.println(id);     
    }

I need my "testRemote" function to return a value, and I capture that value after the call, as an example:

Javasctript:alert(myRemoteCommand([{name:"id", 1}]));

Bean:

public String testRemote()
    {
        String[] id = JSFUtil.getRequestParameterMap().get("id");
        System.out.println(id);     
        return “Test Success”;
    }
  • 2

    Leonardo, welcome to [en.so]. Here the questions should be posted only in Portuguese, click on [Edit] in your question and translate that we will help you or, if you really want to post in English, you should go to [so].

1 answer

0

Well you can do the following:

public String testRemote()
{
    String[] id = JSFUtil.getRequestParameterMap().get("id");
    System.out.println(id); 
    RequestContext.getCurrentInstance().execute("alert(myRemoteCommand([{name:'id', 1}]));");
    return “Test Success”;
}

Within the execute you can have any Javascript. I believe that remoteCommand no return event.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.