segunda-feira, 15 de julho de 2013

Javascript function calling the Managed bean. And passing parameters.


Primefaces provide an component to make action reguest to the managed bean using JavaScript. The remotecomnand can make it for you, using some java script function you can make one request to server side.

Function to call:

<script type="text/javascript">
//Message is a FacesMessage
    function testRemote2(message) {
        var text = message.detail;
        test([{name: 'data', value: text}]);
    }
</script>


Or by CommandLink:
<p:commandLink value = "send"  onclick="test([{name:'data',value:10}]);

 This  jsf command make all for you.
<p:remoteCommand name="test" actionListener="#{viewController .messageRecever}"></p:remoteCommand>
And the the bean class is like this.

@ManagedBean
@SessionScoped
public class ViewController implements Serializable {

public void messageRecever() {
        FacesContext context = FacesContext.getCurrentInstance();
        Map<String, String> param = context.getExternalContext().getRequestParameterMap();
        message.add(param.get("data"));
    }



 }

Nenhum comentário:

Postar um comentário