I’m trying to submit a form when a selectOneRadio value is selected. I have the code below, but it’s not getting inside my #{contentEditorBacking.addNewsArticle}.
Does anyone know how i can get into the method when a selectOneRadio is clicked?
<p:panel header="News Article Title">
<h:panelGrid columns="2">
<h:outputLabel for="title" value="Title" style="font-weight: bold;"/>
<p:inputText id="title" required="true" value="#{contentEditorBacking.newsTitle}" />
<h:outputLabel value="Site" />
<p:selectOneRadio value="#{contentEditorBacking.selectedNews}" layout="pageDirection" onchange="submit()">
<f:selectItem itemLabel="Public" itemValue="Public" />
<f:selectItem itemLabel="Member" itemValue="Member" />
</p:selectOneRadio>
<p:commandButton value="submit" action="#{contentEditorBacking.addNewsArticle}" />
</h:panelGrid>
</p:panel>
Two problems:
clickevent instead.<p:commandButton>is by default an ajax button which isn’t prepared for synchronous submits like as performed by JSsubmit().Just use
<p:ajax>instead so that the submit is performed by ajax. Note that you don’t need to specify theeventattribute, it defaults toclickalready.Update as per the comments, you seem to want to navigate to another page with a parameter. The
addNewsArticle()method should then look like as follows so that it is compatible with both<p:ajax listener>and<p:commandButton action>.