-
1. Re: How to skip validation when clicking a selectOneMenu to update or clear a second one?
healeyb Jul 5, 2012 10:06 PM (in response to ealonso04)Some of the things you're saying aren't quite right, but you need to post the code up if you want to resolve the problem.
The usual problem is that the first selectOneMenu doesn't render= the second.
Regards,
Brendan.
-
2. Re: How to skip validation when clicking a selectOneMenu to update or clear a second one?
liuliu Jul 6, 2012 3:31 AM (in response to ealonso04)did you try execute=@this?i think there is a tutorial about this.
-
3. Re: How to skip validation when clicking a selectOneMenu to update or clear a second one?
ealonso04 Jul 6, 2012 10:49 AM (in response to ealonso04)Hi guys!
This is a snapshot of the code I have:
<h:selectOneMenu id="productos" required="true" value="#{sesion.idProducto}" requiredMessage="El CAMPO PRODUCTO ES REQUERIDO." valueChangeListener="#{catalogServices.getRequisitionTypebyProductId}"> <f:selectItem itemLabel="-- Seleccione una opcion --" /> <f:selectItems value="#{sesion.variables.products.items}" var="prod" itemLabel="#{prod.description}" itemValue="#{prod.id}" /> <a4j:ajax event="valueChange" render="tiposSolicitud" execute="@this"> </a4j:ajax> <f:validateRequired /> </h:selectOneMenu> <rich:message for="productos" /> <h:selectOneMenu id="tiposSolicitud" value="#{sesion.idTipoSolicitud}" requiredMessage="El CAMPO TIPO DE SOLICITUD ES REQUERIDO." valueChangeListener="#{catalogServices.getInquiryByFilter}" required="true"> <f:selectItem itemLabel="-- Seleccione una opcion --" /> <f:selectItems value="#{sesion.tiposSolicitud}" var="tipoSol" itemLabel="#{tipoSol.description}" itemValue="#{tipoSol.id}" /> <a4j:ajax event="valueChange" render="tramites" execute="@this" /> <f:validateRequired />
So what I want to get working basically is, if I select the first item in "productos" which is just like a default item ('-- Seleccione una opcion --'), I want the second component "tiposSolicitud" to be clear in case if it has a selected item.
But now that doesn't work because when I do that, the validation fires up and tells me that I need to select an item, since the first item doesn't have an itemValue and it is checked like required.
I hope to be understandable.
Thanks!
-
4. Re: How to skip validation when clicking a selectOneMenu to update or clear a second one?
healeyb Jul 6, 2012 11:47 AM (in response to ealonso04)which validation fails, the first or second selectOneMenu? Anyway, I think you need to give
<f:selectItem itemLabel="-- Seleccione una opcion --" />
an itemValuethat is guaranteed to not occur in the selectItems, then it won't fail validation. Then when the
special value is detected in the VCL
#{catalogServices.getRequisitionTypebyProductId}
you can clear
#{sesion.idTipoSolicitud}
. When the 2nd selectOneMenu is rerenderedit won't have a value and the problem should be solved.
Regards,
Brendan.
-
5. Re: How to skip validation when clicking a selectOneMenu to update or clear a second one?
ealonso04 Jul 6, 2012 12:05 PM (in response to ealonso04)The first selectOneMenu.
-
6. Re: How to skip validation when clicking a selectOneMenu to update or clear a second one?
healeyb Jul 6, 2012 12:19 PM (in response to ealonso04)Hi, I updated my reply.
-
7. Re: How to skip validation when clicking a selectOneMenu to update or clear a second one?
ealonso04 Jul 6, 2012 12:22 PM (in response to ealonso04)Hi Brendad!
You are right! If a give an itemValue to
<f:selectItem itemLabel="-- Seleccione una opcion --" />
let's say itemValue="0", the validation won't occur and, as you said, when the special value is detected in theVCL
#{catalogServices.getRequisitionTypebyProductId}
I can clear#{sesion.idTipoSolicitud}
but, what if I do a Submit having selected the<f:selectItem itemLabel="-- Seleccione una opcion --" />
item?It should tell me that "productos" is required, since I don't have a selected item, different from
"-- Seleccione una opcion --"
. Do you know what I mean?Or I think I could do what you say and validate the required validation in the bean side, sending a FacesMessage if I detect the itemValue has "0" as its value.
What do you think?
-
8. Re: How to skip validation when clicking a selectOneMenu to update or clear a second one?
healeyb Jul 6, 2012 12:55 PM (in response to ealonso04)Why not, instead of using required="true" use a custom validator, then you can do what you want. The way I'd do this
myself would be to have
<f:selectItem itemLabel="-- Seleccione una opcion --" noSelectionOption="true"/>
and then if a user selects something, well, so be it and the 2nd menu is populated. I can't really see a great usefulness
of being able to clear any selection made, but if you need to you could have a Clear button or link on the page.
-
9. Re: How to skip validation when clicking a selectOneMenu to update or clear a second one?
ealonso04 Jul 9, 2012 3:40 PM (in response to ealonso04)I agree with you, but this is a requirement from QA, you know how the testers are.
Using the
noSelectionOption="true"
what if the user selects the first item ""-- Seleccione una opcion --"
" ? It won't call to the bean method, am I wrong?