











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of the struts validation framework and dynaactionform in advanced java programming. It covers the issues addressed by dynaactionform, the configuration and usage of dynaactionform and validation framework, the types supported by dynaactionform, and the validation process. The document also includes examples from struts-config.xml and struts-examples.
Typology: Slides
1 / 19
This page cannot be seen from the preview
Don't miss anything!












Lecture 15 - Struts Validation Framework, DynaActionForm
How to configure and use validation framework validations-rules.xml validations.xml How to use DynaActionForm with validation framework Client side validation with JavaScript I 18 N and validation Custom validation
Why DynaActionForm?
ActionForm class has to be created in Java programming language For each HTML form page, a new ActionForm class has to be created Every time HTML form page is modified (a property is added or removed), ActionForm class has to be modified and recompiled
What is DynaActionForm?
extends ActionForm class
Properties are configured in configuration file rather than coding reset() method resets all the properties back to their initial values You can still subclass DynaActionForm to override reset() and/or validate() methods Version exists that works with Validator framework to provide automatic validation
Example from struts-examples **<form-beans>
Types Supported by DynaActionForm java.lang.BigDecimal, java.lang.BigInteger boolean and java.lang.Boolean byte and java.lang.Byte char and java.lang.Character java.lang.Class, double and java.lang.Double float and java.lang.Float int and java.lang.Integer long and java.lang.Long short and java.lang.Short java.lang.String java.sql.Date, java.sql.Time, java.sql.Timestamp
You can subclass and override validate() method but it is not recommended
Use DynaValidatorForm class (instead of DynaActionForm class) DynaValidatorForm class extends DynaActionForm and provides basic field validation based on an XML file
**<form-beans>
public final class SubscriptionForm extends ActionForm { ... public String getAction() { return (this.action); } public void setAction(String action) { this.action = action; } ... public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ... } ... }
struts-config.xml: Regular ActionForm class (actually extension of it)
Why Struts Validation Framework?
You have to write validate() method for each ActionForm class, which results in redundant code Changing validation logic requires recompiling
Validation logic is configured using built-in validation rules as opposed to writing it in Java code
Allows declarative validation for many fields Formats Dates, Numbers, Email, Credit Card, Postal Codes Lengths Minimum, maximum Ranges Regular expressions
Validation Framework: How to configure and use Validation framework?