I don’t know why Ajax is not working in my JSF files.Even I have a latest Mojarra which is 3.2.13 in my GlassFish. Here is my code
<h:head></h:head>
<h:body>
<h:panelGroup id="panel" rendered="#{chartBean.showCharts}">
<p:barChart id="basic" value="#{chartBean.categoryModel}"
legendPosition="ne" title="Basic Bar Chart" min="0" max="200"
style="height:300px" />
</h:panelGroup>
<h:commandButton value="Display Chart" action="#{chartBean.createCategoryModel}">
<f:ajax render="panel"/>
</h:commandButton>
</h:body>
Now when I run this code, button doesn’t work.
Another thing, if I change my code like remove panel and just render on barchart like and placed it in
<f:ajax render="basic"/><form>
then it throws NullPointerException. Because it render the chart and expect value from chartBean.categoryModel. Now AFAIK it should not be rendered because of ajax.
I am unable to understand ajax behavior in JSF. I also tried <f:ajax execute="@form" render="basic"> but it didn’t work too. How is this caused and how can I solve it?
You cannot re-render a component that is not there on your page at the time you click the ajax button.
A simple solution would be to move the rendered attribute from the
h:panelGroupto thep:barChart. Then the panelGroup will always be rendered and JSF finds it during your ajax request.