13 Copyright © 2004, Oracle. All rights reserved. Adding Validation and Error Handling.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

Struts Portlet Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Struts Portlet Adding an Action Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without.
Web Development with Karsten Schulz Terp-Nielsen Master Principal Sales Consultant Oracle Denmark.
Apache Struts Technology
Web MVC-2: Apache Struts Rimon Mikhaiel
MVC Frameworks Alternatives to coding the MVC pattern.
Struts1 Apache Struts Dr Jim Briggs. Struts2 What is Struts? Struts is an open source framework for building Java web applications Supports MVC/Model.
DT211/3 Internet Application Development JSP: Processing User input.
Struts Basics SSE USTC Qing Ding. Agenda What is and Why Struts? Struts architecture – Controller: Focus of this presentation – Model – View Struts tag.
Apache Struts Technology A MVC Framework for Java Web Applications.
Struts. Agenda Preface Struts and its components An example The architecture required for Struts Applications.
UNIT-V The MVC architecture and Struts Framework.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Lesson 8 Creating Forms with JavaScript
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
JavaScript Form Validation
 2004 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
WEB DESIGN AND PROGRAMMING Introduction to Javascript.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
BEST PRACTICES - Java By Configuration Use global-forwards/results Helps to avoid duplicate jsp files and redundancy forward mapping.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
Author: DoanNX Version 2.0/Time: 30’. The ways to solve it There are 2 main ways:  Client-side: Using JavaScript (now one very good option is JQuery).
Telerik Software Academy ASP.NET Web Forms Data Validation, Data Validators, Validation Groups Telerik Software Academy
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
Introduction to MVC and the Jakarta Struts Framework By Gyanendra Dwivedi Software Consultant.
Basic Struts Architecture Client Server Database Request Response Control View Model Server Struts Framework.
Jakarta Struts Presented by Object Computing, Inc. (OCI) Written by Greg Elliott
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
8/15/2003System Specialists Corporation How to implement BC4J with the Struts Framework Eugene Sicat Technical Architect/Project Manager System Specialists.
Struts J2EE web application framework “ Model 2 ” Model View Controller Controller Servlet Key features XML metadata Struts taglib Simplified form validation.
Fall CIS 764 Database Systems Design L8. Web ….
Using Client-Side Scripts to Enhance Web Applications 1.
How to Build a Struts Application with JBuilder 9.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Forms with Spring MVC Handling Form.
JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)
Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications.
Struts An Open-source Architecture for Web Applications Facilitator: Tripti Shukla.
REVOLUTION TO NEXT GENERATION Struts2.0 20/02/ Avishek Arang ::
J2EE Struts 1 3 Struts: Introduction 1 4 Once you’ve coded a lot of JSP applications, you find yourself doing a lot of repetitive things. Also,
Page 1 Controller Action2.java Struts- config. xml Mappings Business Logic Layer Data Layer View Layer Business Bean 1 Jsp Engine Jsp 1 Action3.java Action4.java.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Preface IIntroduction Objectives I-2 Course Overview I-3 1Oracle Application Development Framework Objectives 1-2 J2EE Platform 1-3 Benefits of the J2EE.
11 Copyright © 2004, Oracle. All rights reserved. Customizing Actions.
Basic Portlet Copyright © 2000 – 2007 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Struts Framework Day-2 Ashok Chakravarti. DataSource Usage Sample Struts-config.xml …
14 Copyright © 2004, Oracle. All rights reserved. Enhancing the User Interface.
17 Copyright © 2004, Oracle. All rights reserved. Deploying an ADF Application.
Implementation Struts Framework for well-architectured web applications Model-View-Controller design pattern.
6 Copyright © 2004, Oracle. All rights reserved. Adding Custom Validation.
15 Copyright © 2004, Oracle. All rights reserved. Adding JAAS Security to the Client.
8 Copyright © 2004, Oracle. All rights reserved. Making the Model Secure.
Text INTRODUCTION TO ASP.NET. InterComm Campaign Guidelines CONFIDENTIAL Simply Server side language Simplified page development model Modular, well-factored,
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
22 Copyright © 2009, Oracle. All rights reserved. Filtering Requests in Oracle Business Intelligence Answers.
Struts2 Validation using XML Approach. May 12, 2011 Need For Validation Validation can be defined as the assessment of an action so as to ensure that.
Securing Web Applications Lesson 4B / Slide 1 of 34 J2EE Web Components Pre-assessment Questions 1. Identify the correct return type returned by the doStartTag()
Chapter 2 Java Struct 2. Content Basic MVC Architecture Struts 2 Overview Struts 2 - Architecture.
2 Copyright © 2004, Oracle. All rights reserved. ADF Development Process.
12 Copyright © 2004, Oracle. All rights reserved. Using ADF Struts Components.
17 Copyright © 2004, Oracle. All rights reserved. Integrating J2EE Components.
Apache Struts Technology A MVC Framework for Java Web Applications.
5 Copyright © 2004, Oracle. All rights reserved. PL/SQL Server Pages.
V Web Tier Architecture MVC and Struts. v First, there were servlets And things were good Faster than CGI programs More scalable with built-in.
Struts 2 Development. Topics  Roles in Struts Development  Control Flow  Actions  Struts 2 Views and Target  Struts 2 Custom Tags  Validation 
Unit 6-Chapter 2 Struts.
Struts BY: Tejashri Udavant..
Presentation transcript:

13 Copyright © 2004, Oracle. All rights reserved. Adding Validation and Error Handling

13-2 Copyright © 2004, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Validate form input Use declarative validation Use client-side validation Utilize control hints to modify the view

13-3 Copyright © 2004, Oracle. All rights reserved. Overview of Validation Method Validators, Control Hints ADF Business Components Struts Form Bean Struts Action Form Bean validate() method, Struts Validator JSP JavaScriptNew Validation Methods

13-4 Copyright © 2004, Oracle. All rights reserved. Need for Validation In Web applications, the user usually does not receive training on how to complete fields correctly. Thus, an application must provide feedback to the user for these types of actions: Entering required values Specifying values within a specified range Comparing values –For example, Password1 must match Password2.

13-5 Copyright © 2004, Oracle. All rights reserved. Client-Side Validation To perform validation by using Struts, you must: 1.Create a form bean class 2.Overwrite the form bean validate() method, passing an error to the action 3.Create the error message in ApplicationResources.properties 4.Add the input attribute for the form to the action to indicate where the error message should appear

13-6 Copyright © 2004, Oracle. All rights reserved. Form Bean Validation Method The form bean contains a validate() method for validating form fields. Overwrite this method to perform custom validation: public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); if ((username == null) || (username.trim().equals(""))) { errors.add("username", new ActionError("error.username.required")); } return errors; }

13-7 Copyright © 2004, Oracle. All rights reserved. Creating the Error Message To display the error message, specify the message in ApplicationResources.properties : Define where the error message is to be displayed by using the input attribute: error.username.required=The Username Value must be Supplied

13-8 Copyright © 2004, Oracle. All rights reserved. Printing Errors in the JSP Ensure that the JSP contains an tag: Note that you can specify the property attribute of the tag to print only the corresponding error: … …

13-9 Copyright © 2004, Oracle. All rights reserved. Validating Actions A second type of validation is to overwrite the execute method in the action class. This type of validation is useful when: You have previously created classes that check the validity of a given value You do not want the form values to be reset after validation The validation logic is complex

13-10 Copyright © 2004, Oracle. All rights reserved. Creating a Validation Class The first step in validating user input is to create a method for validation. This can be done in a simple class file, as shown: package view; public class LoginValidation { boolean checkUsernamePassword(String un, String pw) { if ( un.equals("scott") && pw.equals("tiger") ) return true; else return false; }

13-11 Copyright © 2004, Oracle. All rights reserved. The execute() Method To validate user input in the action class, overwrite the execute() method, calling your validation method: public ActionForward execute… { LogonActionForm logonForm = (LogonActionForm) form; String un = logonForm.getUsername(); String pw = logonForm.getPassword(); LoginValidation loginvalidation = new LoginValidation(); if ( loginvalidation.checkUsernamePassword(un,pw)) { return mapping.findForward("success"); } else return mapping.findForward("failure"); }

13-12 Copyright © 2004, Oracle. All rights reserved. Validation Results 2. User enters no data (form bean validation). 1. User enters incorrect login (action validation). 3. User enters correct login.

13-13 Copyright © 2004, Oracle. All rights reserved. Struts Validator Declaratively validate form fields by using the Struts Validator. The validator plug-in: Is XML based – validator-rules.xml (Validation rules) – validations.xml (Usages) Defines rules for each field in a form bean Can provide client validation using JavaScript Is extensible

13-14 Copyright © 2004, Oracle. All rights reserved. Setting Up the Struts Validator 1.Specify the validator class in the tag of struts-config.xml. 2.Add validation-rules.xml to your project. 3.Modify the form bean class to subclass ValidatorForm or DynaValidatorForm. 4.Create a usage file to specify form field rules. 5.Add error messages to ApplicationResources.properties.

13-15 Copyright © 2004, Oracle. All rights reserved. Utilizing the Struts Validator Add ValidatorPlugIn to the tag and specify the path for validator-rules.xml and validation.xml :

13-16 Copyright © 2004, Oracle. All rights reserved. Utilizing the Struts Validator Specify the form bean to use the Struts Validator by subclassing ValidatorForm or DynaValidatorForm : Create validation.xml to validate form fields, and ensure that each form field to be validated contains an entry in ApplicationResources.properties : import org.apache.struts.validator.ValidatorForm; public class LogonActionForm extends ValidatorForm { … Logon.username=username Logon.password=password

13-17 Copyright © 2004, Oracle. All rights reserved. validation.xml : Example <!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN" " >

13-18 Copyright © 2004, Oracle. All rights reserved. Struts Validator Output Validator messages can be displayed on the page or in a JavaScript window:

13-19 Copyright © 2004, Oracle. All rights reserved. Exception Handling Exception handling is implemented by: 1.Creating a class for exception handling, which subclasses org.apache.struts.action.ExceptionHandler 2.Overriding the execute() method to process the exception 3.Returning an ActionForward object 4.Configuring the exception handler in the struts- config.xml file 5.Creating an exception message in ApplicationResources.properties

13-20 Copyright © 2004, Oracle. All rights reserved. JavaScript JavaScript is supported in JDeveloper as a simple way to incorporate validation.

13-21 Copyright © 2004, Oracle. All rights reserved. Enhancing the View Use control hints to modify the way an attribute is displayed in a client.

13-22 Copyright © 2004, Oracle. All rights reserved. Summary In this lesson, you should have learned how to: Validate form input using: –The validate() method –The action class –The Struts Validator Develop JavaScript validation Customize the view by using control hints

13-23 Copyright © 2004, Oracle. All rights reserved. Practice 13-1: Overview This practice covers the following topics: Validating form fields by using the validate() method Creating validation methods Calling validation methods from actions Utilizing the Struts Validator Handling exceptions

13-24 Copyright © 2004, Oracle. All rights reserved. Practice 13-1

13-25 Copyright © 2004, Oracle. All rights reserved. Practice 13-1

13-26 Copyright © 2004, Oracle. All rights reserved. Practice 13-1