Struts Validation Framework and DynaActionForm in Advanced Java Programming, Slides of Java Programming

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

2011/2012

Uploaded on 08/09/2012

dhanyaa
dhanyaa 🇮🇳

4.7

(3)

60 documents

1 / 19

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Advanced Java Programming
Lecture15-Struts Validation Framework,
DynaActionForm
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13

Partial preview of the text

Download Struts Validation Framework and DynaActionForm in Advanced Java Programming and more Slides Java Programming in PDF only on Docsity!

Advanced Java Programming

Lecture 15 - Struts Validation Framework, DynaActionForm

Topics

 DynaActionForm

 Validation Framework

 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?

 Issues with using ActionForm

 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

 DynaActionForm support is added to Struts 1.1 to

address these issues

What is DynaActionForm?

 org.apache.struts.action.DynaActionForm

 extends ActionForm class

 In DynaActionForm scheme,

 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

How to perform Validation with

DynaActionForm?

 DynaActionForm does not provide default behavior

for validate() method

 You can subclass and override validate() method but it is not recommended

 Use Validator Framework

 Use DynaValidatorForm class (instead of DynaActionForm class)  DynaValidatorForm class extends DynaActionForm and provides basic field validation based on an XML file

Example from strut-example sample

application

**<form-beans>

**

SubscriptionForm class

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?

 Issues with writing validate() method in ActionForm

classes

 You have to write validate() method for each ActionForm class, which results in redundant code  Changing validation logic requires recompiling

 Struts validation framework addresses these issues

 Validation logic is configured using built-in validation rules as opposed to writing it in Java code

What is Struts Validation Framework?

 Originated from “ generic ” Validator framework from

Jakarta

 Struts 1.1 includes it by default

 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?