wood burning stoves 2.0*
The moose likes JSF and the fly likes Custom validation ignored Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Custom validation ignored" Watch "Custom validation ignored" New topic
Author

Custom validation ignored

Gina vernon
Ranch Hand

Joined: Jan 16, 2009
Posts: 108
Hi,
I have a login page where the page is submitted via a command button action attribute. The attribute points to a method that processes the page.
A username text box on the page has a custom validator that validates the username format which is an email. When an incorrect format is entered the validator does not throw a validator error in the PHASE PROCESS_VALIDATIONS phase. Instead it goes onto the PHASE INVOKE_APPLICATION phase where it throws an authentication error.
How do I get the page to throw the validation error?

Thanks.
suresh dasari
Ranch Hand

Joined: Oct 05, 2009
Posts: 121

Hi Gina,

Have you used immediate attribute by any chance in the command button?
as you said it is a custom validation, have you registered the custom validation in configuration file, could you post the login page code?


Sun Certified Java Programmer with 93 percent
Gina vernon
Ranch Hand

Joined: Jan 16, 2009
Posts: 108
Suresh,
I did not use the immediate attribute and yes the validator is registered. When I debug I can actually see the application go throuhg each line of the validator but just doesn't throw the error it just goes on to the submit action. Here is the code:
JSF:



Validator:



Thanks.
suresh dasari
Ranch Hand

Joined: Oct 05, 2009
Posts: 121

Gina,

your adding the message to facesmessages but not throwing exception, thats why control is directly going to action method.

you should throw the vlidatorException, see the code below:
Gina vernon
Ranch Hand

Joined: Jan 16, 2009
Posts: 108
Suresh, here is the my modified code as per your post. It still does not work.




Thanks.
suresh dasari
Ranch Hand

Joined: Oct 05, 2009
Posts: 121

Hi Gina,

I tried from my workspace, its perfectly working, something else is wrong. The code perfectly works.
is the control is going to validator method, if that is the case its very general that whenever an exception is thrown it shouldnt go to backingbean.

Gina vernon
Ranch Hand

Joined: Jan 16, 2009
Posts: 108
Suresh, did you setup the component exactly as in my jsp code above? If not, could you please try that?

The validation code is working, but the error message is still not seen. So, when I enter an invalid email, 'Email required message' is thrown, not the validation message.

I dont think I included this in my posts, but since the component uses the binding attribute and not the value attribute the following code needs to be added to the set accessor method of the component:


If not the h:message tag throws a standard error message when the field is empty.

Thanks.
Gina vernon
Ranch Hand

Joined: Jan 16, 2009
Posts: 108
I did some further debugging and generated the following phase and messages information:



The validator messages is enqueued in the RENDER_RESPONSE phase. I read on some forum I can't remember that messages that are enqueued in this phase are not displayed.
suresh dasari
Ranch Hand

Joined: Oct 05, 2009
Posts: 121

I think you are making things complicated, Is there any specific reason of using binding attribute for the email?
I guess emailogval is a string variable how come you can use emailogval.getClientId(----) method.
without using a value attribute how can JSF set error messages wrt to that pirticular control.

could you please make it clear?

Thanks,
suresh.
Gina vernon
Ranch Hand

Joined: Jan 16, 2009
Posts: 108
Ok, I finally got what I was doing wrong. The code in the set accessor method was messing up the message queue. Once I got rid of it, everything worked fine.
Thanks, Suresh for your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Custom validation ignored