Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Struts 1.2 Validator and DispatchAction

  Asked By: Bastet    Date: Jun 29    Category: Java    Views: 4249
  

Apparently, it seems like Struts validator have some problems while Action class extends DispatchAction.
As I searched the net I found some tricks in which the "validation.xml" was involved but I guess as I'm using Struts 1.2 I do not have any "validation.xml".
So, anyway, if anybody shares his knowledge of how to accomplish this with clear detailed directions, I'd be grateful.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Daya Sharma     Answered On: Jun 29

your version of struts  supports validation  and must have validation.xml
Struts Framework provides the functionality to validate the form data. It can be use to validate the data on the users browser as well as on the server side. Struts Framework emits the java scripts and it can be used to validate the form data on the client browser. Server side validation of the form can be accomplished by sub classing your From Bean with DynaValidatorForm class.
The validator  framework was developed by David Winterfeldt as third-party add-on to Struts. Now the Validator framework is a part of Jakarta Commons project and it can be used with or without Struts. The Validator framework comes integrated with the Struts Framework and can be used without doing any extra settings.

Validator uses the xml  file to pickup the validation rules to be applied to an form. In XML validation requirements are defined applied to a form. In case we need special validation rules not provided by the validator framework, we can plug in our own custom validations into Validator.
The Validator Framework uses two XML configuration files validator-rules.xml and validation.xml. The validator-rules.xml defines the standard validation routines, these are reusable and used in validation.xml. to define the form specific validations. The validation.xml defines the validations applied to a form bean.

 
Answer #2    Answered By: Viren Rajput     Answered On: Jun 29

OK, I did all it takes to setup the validation  framework and it does work fine.
BUT there's still Two little problems  which is not solved for me and in order tell you those, let me bring up this sample:

Suppose I have an action  class as follows:


public class  EditPartAction extends DispatchAction {

public ActionForward createPart(...params...) {

//takes you to createPart.jsp
return mapping.findForward("createPart");
}

public ActionForward editPart(...params...) {

//takes you to editPart.jsp
return mapping.findForward("editPart");
}
}

and a ActionForm class as follows:

public class EditPartForm extends ValidatorForm {
private String partCode;
private String partName;

//and getter and setter methods
}


Now, As you know, to setup validation framework properly,
in <action> element of your struts-config.xml, you have to set
the input property to the page where your form is placed,
and also set the validate property to "true" as following:

<action
attribute="editPartForm"
validate="true"
input="/system/sentinel/part/createPart.jsp"
name="editPartForm"
parameter="do"
path="/editPart"
scope="request"
type="com.ns.prsnt.struts.action.EditPartAction">

Well, the questions are:
1- What if I need to validate both forms in insertPart.jsp and createPart.jsp?

2- when I use validation for only the createPart.jsp,
it validates the form fields and displays errors even when I'm visiting the page for the first time. Why?

 
Didn't find what you were looking for? Find more on Struts 1.2 Validator and DispatchAction Or get search suggestion and latest updates.