I have a form where I have a rich:select
whether they choose option A or option B an h:inputText
is rendered.
Initially the h:inputText
corresponding to option A is rendered and if I leave it blank the requiredMessage
appears and everything is OK.
Now when I select the second option of the rich:select
the h:inputText
for option B is rendered but if I leave it blank the requiredMessage
doesn't appear.
What am I missing?
My xhtml code is as follows:
<h:panelGrid columns="3">
<h:outputLabel for="tipoPersona">Tipo de persona</h:outputLabel>
<rich:select id="tipoPersona"
required="true" value="#{userInformationController.tipoPersona}"
requiredMessage="Seleccione el tipo de persona"
defaultLabel="Seleccione una opción">
<f:selectItems value="#{userInformationController.tipoPersonaOpciones}"/>
<f:ajax event="blur" render="tipoPersonaMessage"/>
<f:ajax event="selectitem"
render="outputLabelCURP inputTextCURP messageCURP outputLabelRFC inputTextRFC messageRFC"
listener="#{userInformationController.doRenderCURP}"/>
</rich:select>
<rich:message id="tipoPersonaMessage" ajaxRendered="true"
for="tipoPersona"/>
<a4j:outputPanel id="outputLabelCURP">
<h:outputLabel for="CURP" value="CURP"
rendered="#{userInformationController.curpRendered}"/>
</a4j:outputPanel>
<a4j:outputPanel id="inputTextCURP">
<h:inputText id="CURP" required="true"
requiredMessage="Introduzca el CURP"
rendered="#{userInformationController.curpRendered}">
<f:ajax event="blur" render="curpMessage"/>
</h:inputText>
</a4j:outputPanel>
<a4j:outputPanel id="messageCURP">
<rich:message id="curpMessage" ajaxRendered="true"
for="CURP"
rendered="#{userInformationController.curpRendered}"/>
</a4j:outputPanel>
<a4j:outputPanel id="outputLabelRFC">
<h:outputLabel for="RFC" value="RFC"
rendered="#{not userInformationController.curpRendered}"/>
</a4j:outputPanel>
<a4j:outputPanel id="inputTextRFC">
<h:inputText id="RFC" required="true"
requiredMessage="Introduzca el RFC"
rendered="#{not userInformationController.curpRendered}">
<f:ajax event="blur" render="rfcMessage"/>
</h:inputText>
</a4j:outputPanel>
<a4j:outputPanel id="messageRFC">
<rich:message id="rfcMessage" ajaxRendered="true"
for="RFC"
rendered="#{not userInformationController.curpRendered}"/>
</a4j:outputPanel>
</h:panelGrid>
UPDATE
I have made some changes on the UI and now I have this
<fieldset>
<legend>Datos SURI</legend>
<h:panelGrid columns="3">
<h:outputLabel for="tipoPersona">Tipo de persona</h:outputLabel>
<rich:select id="tipoPersona"
required="true" value="#{userInformationController.tipoPersona}"
requiredMessage="Seleccione el tipo de persona"
defaultLabel="Seleccione una opción">
<f:selectItems value="#{userInformationController.tipoPersonaOpciones}"/>
<f:ajax event="blur" render="tipoPersonaMessage"/>
<f:ajax event="selectitem"
render="outputLabelCURP inputTextCURP messageCURP
outputLabelRFC inputTextRFC messageRFC
datosPersonaFisica datosPersonaMoral"
listener="#{userInformationController.doRenderTipoPersona}"/>
</rich:select>
<rich:message id="tipoPersonaMessage" ajaxRendered="true"
for="tipoPersona"/>
<a4j:outputPanel id="outputLabelCURP">
<h:outputLabel for="CURP" value="CURP"
rendered="#{userInformationController.personaFisicaRendered}"/>
</a4j:outputPanel>
<a4j:outputPanel id="inputTextCURP">
<h:inputText id="CURP" required="true"
requiredMessage="Introduzca el CURP"
value="#{userInformationController.curp}"
rendered="#{userInformationController.personaFisicaRendered}">
<f:ajax event="blur" render="curpMessage identificadorSURI"
listener="#{userInformationController.doSearchIdSURI}"/>
</h:inputText>
</a4j:outputPanel>
<a4j:outputPanel id="messageCURP">
<rich:message id="curpMessage" ajaxRendered="true" for="CURP"
rendered="#{userInformationController.personaFisicaRendered}"/>
</a4j:outputPanel>
<a4j:outputPanel id="outputLabelRFC">
<h:outputLabel for="RFC" value="RFC"
rendered="#{userInformationController.personaMoralRendered}"/>
</a4j:outputPanel>
<a4j:outputPanel id="inputTextRFC">
<h:inputText id="RFC" required="true"
requiredMessage="Introduzca el RFC"
value="#{userInformationController.rfc}"
rendered="#{userInformationController.personaMoralRendered}">
<f:ajax event="blur" render="rfcMessage identificadorSURI"
listener="#{userInformationController.doSearchIdSURI}"/>
</h:inputText>
</a4j:outputPanel>
<a4j:outputPanel id="messageRFC">
<rich:message id="rfcMessage" ajaxRendered="true" for="RFC"
rendered="#{userInformationController.personaMoralRendered}"/>
</a4j:outputPanel>
<h:outputLabel for="identificadorSURI">Identificador SURI</h:outputLabel>
<h:inputText id="identificadorSURI" disabled="true"
value="#{userInformationController.identificadorSuri}"/>
</h:panelGrid>
</fieldset>
However, I found that putting my Bean in RequestScope isn't firing the listener on both of the h:inputText
(id='CURP' and id='RFC'), whereas if I put the bean in ViewScope the listener is getting fired and processed correctly.
What I need is to actually have the Bean in RequestScope because I need to create a whole new form whether the user changes the value of the rich:select
. If I keep the scope in ViewScope all the data is kept within the Bean and I will then have to erase the fields when the user changes the value of the select.
Can someone explain to me why is this happening? I could'n figure out what's the trick !
Cheers