• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

validation of more than one field (e.g. password verification)

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to have a page where a user can change his password
e.g. enter the password in one field, and then he has to enter the password again in a second field to make sure that he typed his password correctly.

So, my validation would be a simple comparision that the entries are identical.

I have a backing bean for the values of the fields.

What I want is when the user clicks a button I would simply like to call a verification method in the backing bean that compares the attributes and returns some error if they are not identical.

How can i achieve this? The commandbutton does not have a validator attribute, and calling a method over the action attribute does not seem to work.

All I can find in the internet are simple examples where the value of one field is checked, not that several fields are compared with one validation method.

cheers,

RJ
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ronald,

Originally posted by Ronald Johnson:
I want to have a page where a user can change his password
e.g. enter the password in one field, and then he has to enter the password again in a second field to make sure that he typed his password correctly.

So, my validation would be a simple comparision that the entries are identical.

I have a backing bean for the values of the fields.

What I want is when the user clicks a button I would simply like to call a verification method in the backing bean that compares the attributes and returns some error if they are not identical.

How can i achieve this? The commandbutton does not have a validator attribute, and calling a method over the action attribute does not seem to work.

All I can find in the internet are simple examples where the value of one field is checked, not that several fields are compared with one validation method.

cheers,

RJ


-- What you could do is to create another field for your error message at the backing bean. In the validation method verify everithing and if anything is wrong fill your errorMessage field so JSF could render it when returning to the client. An example:

<@ taglibs.... @>
<f:view>
<h:form>
.... your tags
<h:outputText value="#{yourBean.errorField}"/>
</h:form>
</f:view>

And you know the code of your bean to validate your fields.

I hope this could help.
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should be able to compare the fields in your backing bean's action method itself. By the time the action method is called, the password and the verify password fields will already be posted to the backing bean and they will be available for your validation.
After comparing, if it fails your validation, you may choose to redisplay the same page with a message:

Make sure you are using h:messages in order to display this message.

I think there is also another approach to do a combined field validation. In this approach, you should have a dummy hidden field AFTER all your fields that need combined validation. This hidden field should have a validator attribute which will call the validation method of your backing bean.
 
Ronald Johnson
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, my solution was this:



I also found out that in Apache Tomahawk (from version 1.0.5) there exist a tag t:validateEqual that does exactly what i want.

cheers!
 
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic