1 Chính phủ điện tử TS. Phạm Văn Tính Khoa CNTT, ĐH Nông Lâm TP.HCM

Slides:



Advertisements
Similar presentations
CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
Advertisements

Tutorial 6 Creating a Web Form
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Tableau Lab 2 Calculations and Parameters. Data Set The fundraising data set uses a JOIN to combine two worksheets - Funds and Pledges - from one source.
The Web Warrior Guide to Web Design Technologies
Internet Technologies 1 Master of Information System Management Java Server Faces Model/View/Controller Design Pattern for Web Development Slides.
JavaServer Faces. Objectives To implement dynamic web pages with JavaServer Faces (JSF) technology To learn the syntactical elements of JavaServer Faces.
Chapter 4 - Control Structures: Part 1 Outline 4.4Control Structures 4.5The if Selection Structure 4.6The if/else Selection Structure 4.7The while Repetition.
Basics of ASP.NET. 2 © UW Business School, University of Washington 2004 Outline Installing ASP.NET and Web Matrix Data Types Branching Structure Procedures.
Java Server Faces Model/View/Controller Design Pattern for Web Development Slides adapted from “Core JavaServer Faces” by Geary and Horstmann and the J2EE.
Tutorial 14 Working with Forms and Regular Expressions.
Struts 2.0 an Overview ( )
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
XP Tutorial 14 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
JSP Standard Tag Library
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
JavaScript Form Validation
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Tutorial 14 Working with Forms and Regular Expressions.
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Telerik Software Academy ASP.NET Web Forms Data Validation, Data Validators, Validation Groups Telerik Software Academy
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
CSCI 6962: Server-side Design and Programming Validation Tools in Java Server Faces.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
JavaServer Faces Jeff Schmitt October 5, Introduction to JSF Presents a standard framework for building presentation tiers for web applications.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
CSCI 6962: Server-side Design and Programming Introduction to Java Server Faces.
Validation and Rich controls 1www.tech.findforinfo.com.
Chapter 8 Cookies And Security JavaScript, Third Edition.
By: Saurabh Dixit.  Groovy server pages  Taglibs  Validators in grails.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Input, Output, and Processing
CSCI 6962: Server-side Design and Programming AJAX Tools in JSF and ASP.
Using Client-Side Scripts to Enhance Web Applications 1.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
Java Web Development with NetBeans IDE -- Kai Qian Chapter 5 JavaServer Faces (JSF) Technology.
JavaServer Faces: Sample App + Life Cycle Compiled from Sun TechDays workshops (JSF Basics, Web-Tier Codecamp: JavaServer Faces, Java Studio Creator)
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)
JSTL The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates core functionality common to many JSP applications.
HTML Forms. Slide 2 Forms (Introduction) The purpose of input forms Organizing forms with a and Using different element types to get user input A brief.
Chính phủ điện tử TS. Phạm Văn Tính Khoa CNTT, ĐH Nông Lâm TP.HCM
® IBM Software Group © 2006 IBM Corporation Using JSF Mini-Calendar Controls This section describes how to use a JSF Mini-Calendar Control with EGL It.
1 Chính phủ điện tử TS. Phạm Văn Tính Khoa CNTT, ĐH Nông Lâm TP.HCM
CSCI 6962: Server-side Design and Programming JSF DataTables and Shopping Carts.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
Unit 10 – JavaScript Validation Instructor: Brent Presley.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Vijayalakshmi G M Validation Controls.
JavaServer Faces framework Craig McClanahan is presented that created Struts web framework and based on experience gathered designed JavaServer.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Text INTRODUCTION TO ASP.NET. InterComm Campaign Guidelines CONFIDENTIAL Simply Server side language Simplified page development model Modular, well-factored,
SDJ INFOSOFT PVT. LTD. 2 BROWSERBROWSER JSP JavaBean DB Req Res Application Layer Enterprise server/Data Sources.
Tutorial 6 Creating a Web Form
XML Schema – XSLT Week 8 Web site:
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Navigation Mimi Opkins CECS 493 Fall Static Navigation  In a simple web application, navigation is static. That is, clicking a particular button.
Intro to JavaServer Faces Mimi Opkins CECS 493 Fall 2016.
JSF Conversion and Validation
The Expression Language Syntax
Creating Database Objects
Intro to PHP & Variables
Working with Forms and Regular Expressions
Conditions and Ifs BIS1523 – Lecture 8.
Java Programming Language
Creating Database Objects
Presentation transcript:

1 Chính phủ điện tử TS. Phạm Văn Tính Khoa CNTT, ĐH Nông Lâm TP.HCM

2 Conversion and Validation

3Outline  JSF Life-Cycle  Overview of the Conversion and Validation Process  Error Message  Using Standard Converters  Using Standard Validators  Programming with Custom Converters and Validators

4 JSF Life-Cycle

5 5

6 Phases of JSF life cycle  Restore View: recreates the server-side component tree when you revisit a JSF page.  Apply Request Values: copies request parameters into component submitted values.  Process Validations: first converts those submitted values and validates the converted value.  Update Model Values: copies converted and validated values to the model, which is typically denoted in JSF pages with value reference expressions, such as:  Invoke Application: invokes action listeners and actions, in that order, for command components.  Render Response: saves state and loads the next view. The JSF navigation handler forwards or redirects to another JSP page. 6

7 Conversion and Validation Process Look at user input as it travels from the browser form to the beans that make up the business logic.  The user fills in a field of a web form then submit to send the form data - called the request value - to the server  In the "Apply Request Values" phase, the request values are stored in component objects and is called the submitted value.  A conversion process transforms the incoming strings to types of the web application such as int, Date,... The converted values are stored and validated inside the component objects.  After being validated, the "Update Model Values" phase starts, and the local values are stored in beans, as specified by their value references. 7

8 Conversion and validation phases

9 How conversion and validation are performed

10 JSF Standard Converters

11 Using Standard Converters  Example: a web application that is used to process payments. The payment data includes  the amount to be charged  the credit card number  the credit card expiration date

12 Conversion of Numbers and Dates  We attach a converter to the payment amount textfield and tell it to format the current value with at least two digits after the decimal point:  The expired date field uses an f:datetime converter whose pattern attribute is set to the string MM/yyyy. 12

13 JSF 2 convertNumber example  In JSF, “f:convertNumber” is a standard converter, which converts String into a specified “Number” format. In addition, it’s also used as a validator to make sure the input value is a valid number. See following common used examples :  Note : Assuming #{receipt.amount} contains a “0.1” value.

14 JSF 2 convertNumber example 1. minFractionDigits attribute Display the value as “0.10″. 2. pattern attribute Display the value as “0.100″. Note The pattern format is defined in java.text.DecimalFormat

15 JSF 2 convertNumber example 3. currencyCode attribute Display the value as “GBP0.10″. Note: The currencyCode is defined in ISO type=”percent” attribute Display the value as “10%”.

16 JSF 2 public class ReceiptBean implements Serializable{ double amount; public double getAmount() { return amount; } public void setAmount(double amount) { this.amount = amount; } }

17 Attributes of the f:convertNumber AttributeTypeValue type String number (default), currency, or percent pattern String Formatting pattern, as defined in java.text.DecimalFormat maxFractionDigits int Maximum number of digits in the fractional part minFractionDigits int Minimum number of digits in the fractional part maxIntegerDigits int Maximum number of digits in the integer part minIntegerDigits int Minimum number of digits in the integer part integerOnly boolean true if only the integer part is parsed (default: false) groupingUsed boolean True if grouping separators are used (default: true) locale java.util.Locale Locale whose preferences are to be used for parsing and formatting currencyCode String ISO 4217 currency code to use when converting currency values currencySymbol String Currency symbol to use when converting currency values 17

18 Attributes of the f:convertDateTime AttributeTypeValue type String Date (default), time, or both dateStyle String default, short, medium, long, or full timeStyle String default, short, medium, long, or full pattern String Formatting pattern, as defined in java.text.SimpleDateFormat locale java.util.Locale Locale whose preferences are to be used for parsing and formatting timeZone java.util.TimeZone Time zone to use for parsing and formatting  If you use a value binding whose type is either a primitive type, then you don't need to specify any converter. The JSF implementation automatically picks a standard converter.  However, you need to specify an explicit converter for Date values. 18

19 The converter Attribute  An alternate syntax for attaching a converter to a component is to add the converter attribute and ID of the converter This is equivalent to:  Converters with predefined IDs: javax.faces.DateTime, javax.faces.Number, javax.faces.Boolean, javax.faces.Byte, javax.faces.Character, javax.faces.Double, javax.faces.Float, javax.faces.Integer, javax.faces.Long, javax.faces.Short, javax.faces.BigDecimal,javax.faces.BigInteger 19

20 Using Standard Validators  JavaServer Faces has built-in mechanisms that let you carry out the following validations: ─Checking the length of a string ─Checking limits for a numerical value ─Checking that a value has been supplied  For example, to check limits for a numerical value, you use a range validator: 20

21 Standard Validators JSP TagAttributesValidates f:validateDoubleRangeminimum, maximum a double value within an optional range f:validateLongRangeminimum, maximum a long value within an optional range f:validateLengthminimum, maximum a String with a minimum and maximum number of characters  All the standard validator tags have minimum and maximum attributes. You need to supply one or both of these attributes. 21

22 Checking for Required Values  To check that a value is supplied, you supply the attribute required="true" :  All JSF input tags support the required attribute.  You can combine the required attribute with a nested validator: 22 CAUTION: If the required attribute is not set and a user supplies a blank input, then no validation occurs at all! Instead, the blank input is interpreted as a request to leave the existing value unchanged.

23 Validation Approaches  Manual validation ─ Use string properties for bean ─ Do validation in setter methods and/or action controller ─ Return null to redisplay form ─ Create custom error messages and store in FacesMessage ─ Use h:messages to display list of error messages  Implicit automatic validation ─ Use int, double, etc. bean properties. Or add required. ─ System redisplays form if there is conversion error ─ Use h:message to display field-specific error message

24 Validation Approaches  Explicit automatic validation ─ Use f:validateLength, f:validateDoubleRange, f:validateLongRange, or f:validateRegex ─ System redisplays form if failure; use h:message again  Custom validation methods ─ Create FacesMessage, wrap in ValidatorException

25 Conversion and Validation Errors  When a conversion or validation error occurs, the following actions are the result: ─The component whose conversion/validation failed posts a message and declares itself invalid. ─The JSF implementation redisplays the current page immediately after the "Process Validations" phase has completed.  To to show the error messages to the components use h:message and h:messages tag 25

26 Displaying Error Messages  h:message tag show the error messages next to the components that reported them.  A message has two parts: summary and detail. By default, the h:message tag shows the detail. If you want to show the summary message instead, use:  You use the styleClass or style attribute to change the appearance of the error message: or 26

27 Displaying All Error Messages  show a listing of all messages from all components using the h:messages tag.  By default, the h:messages tag shows the message summary but not the message detail.  you can layout attribute the messages are lined up vertically. Otherwise they are simply concatenated. 27

28 Manual Validation

29 Standard System for Error Messages

30 Creating Error Messages: Details

31 Displaying Error Messages: Details

32 Manual Validation: Example

33 Bean Code: String Properties (No Conversion)

34 Bean Code: Numeric Properties (Conversion)

35 Bean Code: Action Controller

36 Bean Code: Action Controller (Continued)

37 Input Form: Displaying Error Messages (enter-bid1.xhtml)

38 Results Page (show- bid1.xhtml)

39 Manual Validation: Results (Bad Input)

40 Implicit Automatic Validation

41 JSF Flow of Control

42 Precedence of Validity Tests

43 Implicit Validation: Example

44 Bean Code: Properties

45 Bean Code: Action Controller  No validation logic in the action controller, so action controller can concentrate on business logic

46 Input Form: Top (enter-bid2.xhtml)

47 Input Form: Continued (enter-bid2.xhtml)

48 Results (Bad Input) Since tests for required attributes take precedence over tests for proper types, the requiredMessage attribute is displayed here

49 Results (Bad Input) Since the value passes the required test, the type test is applied

50 JSF Standard Validators JSP TagAttributes Validates f:validateDoubleRangeminimum, maximum a double value within an optional range f:validateLongRangeminimum, maximum a long value within an optional range f:validateLengthminimum, maximum a String with a minimum and maximum number of characters  All the standard validator tags have minimum and maximum attributes. You need to supply one or both of these attributes. 50

51 Explicit Automatic Validation

52 General Format for Validator Tags

53 Conversion vs. Validation

54 Main Validator and Converter Attributes

55 Explicit Validation: Example

56 Input Form: User ID (enter-bid3.xhtml)

57 Input Form: Keyword (enter-bid3.xhtml)

58 Input Form: Bid Amount (enter-bid3.xhtml)

59 Input Form: Bid Duration (enter-bid3.xhtml)

60 Results (Missing Data)

61 Results (Type Conversion Errors)

62 Results (Explicit Validation Errors)