I am experiencing a problem with Ajax and PrimeFaces.
What the page should do :
-User choses between “Cas 1” and “Cas 2” (radiobuttons)
-Once a case is validated, an Ajax query should display one input text area for “cas 1” and several for “cas 2”. The text in input text area should be saved in a database
What really happens :
-User choses between “Cas 1” and “Cas 2”
-The input text area(s) display correctly on the first time and then wont change again if you switch between “Cas 1” and “Cas 2”. Also, the text isnt saved in the database.
Separately (without the radiobuttons), both “Cas 1” and “Cas 2” work correctly
Here is the code I am using :
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body>
<h:form id="form">
<p:messages id="messages" showDetail="true" autoUpdate="true"/>
<h:panelGrid columns="1" >
<h:outputText value="Cas 1 : sélection « travail identique pour l’ensemble des CDC » ou un seul CDC" />
<h:outputText value=" " />
<h:outputText value="Cas 2 : sélection « travail différent suivant les CDC »" />
<p:selectOneRadio id="CasTrois" value="#{growlBean.casTrois}" required="true">
<f:selectItem itemLabel="Cas 1" itemValue="1" />
<f:selectItem itemLabel="Cas 2" itemValue="2" />
<p:ajax event="change" update="displayTrois" />
</p:selectOneRadio>
</h:panelGrid>
<h:panelGrid columns="1" id="displayTrois">
<c:if test="${growlBean.casTrois == 1}">
<h:outputText value="Expliquer succinctement en quoi consiste l’affaire." />
<h:outputText value="Donner notamment les informations liées à l’affaire mais ne figurant pas dans les CDC." />
<h:outputText value=" " />
<h:outputText value="Exemple" style="font-weight:bold; color: green"/>
<h:outputText value="Relance en quantité 1 de tous les sous-ensembles de tous les CDC" style="font-weight:bold; color: green"/>
<h:panelGrid columns="2">
<h:panelGrid columns="1">
<p:inputTextarea rows="8" cols="100" required="false" validatorMessage="Le champ doit être rempli"
value="#{growlBean.natureDesTravaux}" autoResize="true" >
<p:ajax event="keyup" listener="#{growlBean.setNatureDesTravaux(natureDesTravaux)}"/>
</p:inputTextarea>
</h:panelGrid>
</h:panelGrid>
</c:if>
<c:if test="${growlBean.casTrois == 2}">
<h:outputText value="Expliquer succinctement en quoi consiste l’affaire." />
<h:outputText value="Donner notamment les informations liées à l’affaire mais ne figurant pas dans les CDC." />
<p:dataTable id="TableauNatrureTravaux" value="#{growlBean.listCdcAffaire2}" var="detailCdc" >
<f:facet name="header">
<h:outputText value="Nature des Travaux"/>
</f:facet>
<p:column >
<h:panelGrid columns="1">
<p:outputLabel for="textTravaux" value="#{detailCdc.cdcId.outillageId.numeroOutil} #{detailCdc.cdcId.outillageId.designation}" />
<p:inputTextarea id="textTravaux" rows="8" cols="100" value="#{detailCdc.natureTravauxPourFla}"
autoResize="true" required="false" validatorMessage="test" >
<f:validateLength minimum="1" />
<p:ajax event="keyup" listener="#{detailCdc.setNatureTravauxPourFla(natureTravauxPourFla)}"/>
</p:inputTextarea>
</h:panelGrid>
</p:column>
</p:dataTable>
</c:if>
</h:panelGrid>
</h:form>
</h:body>
Can someone help me trying to refresh the page and save the text?
To have the radio buttons work correctly change your
displayTroiselement to the following, (If this doesn’t resolve it you will need to post your bean information and include the listener):