Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about the validation

 
Mike Phillip
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Mike Phillip
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
simple.
use same page in your input attribute...
 
Mike Phillip
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Is this error message externalised?

In struts-config.xml file


in ApplicationResources.properties file


HTH
V
 
Mike Phillip
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes
 
Mike Phillip
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good to know it worked...

V
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
return new ActionForward(mapping.getInput());


You better use this 'return mapping.getInputForward();'
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic