Two Laptop Bag*
The moose likes Struts and the fly likes DispatchAction and Validator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "DispatchAction and Validator" Watch "DispatchAction and Validator" New topic
Author

DispatchAction and Validator

Suzi Cooper
Ranch Hand

Joined: Jul 23, 2005
Posts: 45
Hey Folks,
I am having some issues with Validator.
Problem : I want to do server side validation with the validator.I am using DispatchAction instead of Action class.If i extend my bean as Actionform, clientside validation works but not server side.If it extends ValidatorForm,it skips all the action methods for both server and client side.If i do manual validation,how do i perform validations based on the the actions.
Somebody plz help!!!
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9963
    
163

Its possible to do validations using ValidatorForm on server side, even if you are using DispatchAction. Can you mention the exact nature of problem that you are facing while doing the same?

Thank you


[My Blog] [JavaRanch Journal]
Suzi Cooper
Ranch Hand

Joined: Jul 23, 2005
Posts: 45
Jaikiran,
The problem is if i extend as Validator Form, the action classes are not read(checked using println stmt) and the incorrect jsp pages are displayed.Here is the scenario : i have a JSP page with 3 buttons(add, edit , view details).Add and Edit load the same page but with some fields being different.I set a hidden param to check if it is add or edit.If i click on add, the jsp page displayed if fine but when i do a SUBMIT with incorrect field values,the validation is not done and the page is displayed in the edit mode.If i do a Cancel, it points to a different jsp page(not specified in mapping)

Any ideas or advise???
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9963
    
163

if i extend as Validator Form, the action classes are not read


This indicates that the validation failed and as a result the control never reached action class

but when i do a SUBMIT with incorrect field values,the validation is not done and the page is displayed in the edit mode


Are you sure the validation is not done? I guess the validation is being done(as the control never reaches your action class). I believe the hidden parameter that you are using for distinguishing add/edit, is causing the edit jsp to be displayed in case of validation errors. Have you checked the value of the hidden parameter, just before rendering the jsp after validations.

Also, it would be helpful if you post the relevant config files and may be your form class(if you have overriden the validate method).

Thank you
Suzi Cooper
Ranch Hand

Joined: Jul 23, 2005
Posts: 45
hey,
mailed the files to u,jaikiran

Any help is appreciated.

Issue is : how do i tell the validator to validate on submission of form and nor on loading of it
Ambily G Nair
Greenhorn

Joined: Aug 21, 2004
Posts: 28
Hi,

For the Dispatch Action ur struts-config.xml entry will be something like this,

<form-bean name="userListForm" dynamic="true" type="form.ListAllUserForm"/>

<action path="/listallusers"
type="test.ListAllUserDispatchAction"
name="userListForm"
scope="request"
validate="true"
parameter="mtc"
input="/pages/userList.jsp"
>
<forward
name="updatesuccess"
path="/listallusers.do?mtc=list"/>
<forward
name="success"
path="/pages/displayallusers.jsp"/>
<forward
name="failure"
path="/pages/userList.jsp"/>

</action>

In this ListAllUserForm will extend ActionForm class and in that class u have to put a validate method as given below.

public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
/**
* create a new Action Errors object to hold any error we discover upon validation of the forms fields.
*/
ActionErrors errors = new ActionErrors();

if (userName == null || userName.trim().length() < 1) {
errors.add("username", new ActionError("errors.required", "LoginName"));
}
if (password == null || password.length() < 1) {
errors.add("username", new ActionError("errors.required", "Password"));
}
return errors;
}

I hope this will help you.

Ambily
Suzi Cooper
Ranch Hand

Joined: Jul 23, 2005
Posts: 45
Ambily,
I have tried what u suggested,but it still does not perform validations on submission of the form.

Any ideas???
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9963
    
163

Issue is : how do i tell the validator to validate on submission of form and nor on loading of it


As far as this issue is concerned, you can you ValidatorActionForm instead of ValidatorForm. For the difference between the 2, have a look at:

http://www.jguru.com/forums/view.jsp?EID=1193949

Regarding, the code snippets that you sent, i am having a look at the same. Could not download the attachments yet, because of rediff server problem. If possible send the same to jai_forums2005@yahoo.co.in
Will have a look at them.

Thank you.
Suzi Cooper
Ranch Hand

Joined: Jul 23, 2005
Posts: 45
Jai,

I have tried using ValidatorActionForm as well.Does not make any difference...
:-(
Ambily G Nair
Greenhorn

Joined: Aug 21, 2004
Posts: 28
Can you send me the code to ambilyg@gmail.com. Let me have a look. Action class ,struts-config.xml part,Form class and jsp
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DispatchAction and Validator
 
Similar Threads
Struts and Validation Framework
using validator with DispatchAction
Validwhen validator client side javascript
Usage of Both DynaValidatorForm and DispatchAction
Validwhen validator java script