-
1. Re: GraphValidator and Validation Groups
snandula Jul 16, 2012 3:33 PM (in response to snandula)Thought i would add an example.
I have a problem i am unable to resolve and thought you could help as i see you have provided input into issues like this.
My environment is JSF2 + RichFaces + Hibernate validator
i have 2 buttons on a page. when i click one button, only one UI Component needs to be validated. when i click the other, it needs to validate the whole form and perform cross field validations.
I believe the best way to do this is using validation groups. I created groups accordingly. I am able to test my bean outside of JSF for validations based on the groups and it all works fine.
But i am not able to specify the groups to the rich graph validator properly. How do i change the validaton groups based on the button clicked?
Please find code below as an example
<rich:graphValidator value="#{caregiverStipendBean.currentItem}"
groups="#{caregiverStipendBean.currentItem.groups}"
summary="Invalid values: ">
<h:panelGrid style="width:80%">
<h:outputText>SSN</h:outputText>
<h:inputText value="#{mybean.ssn}" />
<h:commandButton value="Search SSN"
action="#{caregiverStipendBean.searchCaregiver}" >
</h:commandButton>
<h:outputText>password</h:outputText>
<h:inputText value="#{mybean.password}" />
<h:outputText>reenter password</h:outputText>
<h:inputText value="#{mybean.confirmationpassword}" />
<h:commandButton value="Save"
action="#{caregiverStipendBean.save}" >
</h:commandButton>
</h:panelGrid>
</rich:graphValidator>
As you can see , i have 2 buttons. The save button should validate the entire form and do cross field validation. But the search ssn should only validate the ssn field.
To accomplish this, i created 2 validation groups. One for validating the SSN and the other for validating the remaining fields along with SSN.
How do i change the validation groups based on click of a button? I just provided the example above for simplicity. My actual from is little more components than what i provided in this.
Any help is greatly apprecieated.
Thankyou
Srinivas.
-
2. Re: GraphValidator and Validation Groups
iabughosh Jul 17, 2012 1:56 AM (in response to snandula)hello nadula,
i think you don't have problems with save button, your problem is with search button, you can edit your search button like this :
<h:inputText id="ssnTxt" value="#{mybean.ssn}" />
<a4j:commandButton value="Search SSN"
action="#{caregiverStipendBean.searchCaregiver}"
execute="ssnTxt"
render="@form">
</a4j:commandButton>
by executing only ssnTxt, only ssnTxt will be validated.
regards.
-
3. Re: GraphValidator and Validation Groups
snandula Jul 17, 2012 10:29 AM (in response to iabughosh)I tried what you suggested, but it does not work. I think if i was using the JSF Validators that might work. But i am using the graph validator which validates the entire form and i need to specify the validation groups.
How do i specify different validation groups to the rich graph validator? i tried something like this.
<rich:graphvalidator groups = {#param('GROUPS'} and with the action i was trying to pass a param GROUPS with the required validation group. But that does not work.
I have to use the rich:graphvalidator because JSF2 does not work with hibernate cross field validations.
Can you suggest something?