aspose file tools*
The moose likes Struts and the fly likes about the validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "about the validation" Watch "about the validation" New topic
Author

about the validation

Mike Phillip
Ranch Hand

Joined: Dec 05, 2007
Posts: 37
Hi there, I have some questions about the validation process.

I have this form to register a user, and it uses the the client-side validation framework and aldo the validate method of the form form server-side.

My question is, once the form validates that all fields are well formated, where do I do a validation for check if the username is already chosen, in the form or in the action?

if in the form: doesn't this breaks the mvc pattern? the form will know how the logic works

if in the action: how can I report the "login already in use" to the same page that has the form?

thanks
Vishal Matere
Ranch Hand

Joined: Jan 22, 2008
Posts: 81
In Action class.

Add error message in Action class like this


And write your error page name in <action ----- input="errorPageName">

HTH
V
[ May 13, 2008: Message edited by: Vishal Matere ]

SCJP <br />SCWCD <br />SCBCD <br />SCEA-1
Mike Phillip
Ranch Hand

Joined: Dec 05, 2007
Posts: 37
thanks for reply.

but that way you showed it redirects to another page.

I would like to know if its possible to show the error in the the same page, like errors that says that a field is required and are show in <html:errors>

thanks
Vishal Matere
Ranch Hand

Joined: Jan 22, 2008
Posts: 81
simple.
use same page in your input attribute...
Mike Phillip
Ranch Hand

Joined: Dec 05, 2007
Posts: 37
I'm tryng that. But it doesnt show the error in the page. I do some println to see if the error is added and it prints ok.

but doesn't show the error in the <html:errors/>
Vishal Matere
Ranch Hand

Joined: Jan 22, 2008
Posts: 81

Is this error message externalised?

In struts-config.xml file


in ApplicationResources.properties file


HTH
V
Mike Phillip
Ranch Hand

Joined: Dec 05, 2007
Posts: 37
Yes
Mike Phillip
Ranch Hand

Joined: Dec 05, 2007
Posts: 37
thanks dude, It's working now.

ActionMessages errors = new ActionMessages();
errors.add("userid",new ActionMessage("errors.user.already.exists"));
saveErrors(request,errors);
return new ActionForward(mapping.getInput());
Vishal Matere
Ranch Hand

Joined: Jan 22, 2008
Posts: 81
good to know it worked...

V
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

return new ActionForward(mapping.getInput());


You better use this 'return mapping.getInputForward();'


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: about the validation
 
Similar Threads
form bean and validation.
Struts and Validation Framework
How to suppress client-side validation when field in bind to dojo’s ajax call?
Buttons in same form hitting different servlets
Custom Validation