In the example below, the p: commandButton command starts an ajax request. The JSON object you want to use can be stored in the h: inputHidden field. When p: commandButton exits, the javascript function is called to update the chart. The javascript function will be able to access the JSON object from the h: inputHidden field.
XHTML
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.prime.com.tr/ui"> <h:head> <script type="text/javascript"> function dosomething() { var value = jQuery("#beanvalue").attr('value'); alert(value); } </script> </h:head> <h:body> <h:form prependId="false" > <p:commandButton value="update" action="#{testBean.update}" update="beanvalue" oncomplete="dosomething();" /> <h:inputHidden value="#{testBean.output}" id="beanvalue" /> </h:form> </h:body> </html>
Bean
import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; @ManagedBean @ViewScoped public class TestBean { private String output; public TestBean() { output = "1"; } public void update() { output += "1"; } public String getOutput() { return output; } public void setOutput(String output) { this.output = output; } }
Mark source share