Data transfer and type conversion One of the common tasks of the web application domain was moving and converting data from string-based HTTP to the various.

Slides:



Advertisements
Similar presentations
23-Aug-14 HTML/XHTML Forms. 2 What are forms? is just another kind of XHTML/HTML tag Forms are used to create (rather primitive) GUIs on Web pages Usually.
Advertisements

XP 1 Developing a Basic Web Site Tutorial 2: Web Site Structures & Links.
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Chapter 31 Basic Form-Processing Techniques JavaServer Pages By Xue Bai.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Layer 7- Application Layer
Pemrograman Dasar - Data Types1 THINGS & STUFF Identifier, Variable, Constant, Data type, operator, expression, assignment, javadoc.
1 Software Testing and Quality Assurance Lecture 32 – SWE 205 Course Objective: Basics of Programming Languages & Software Construction Techniques.
Session-02. Index. Jsp in Struts 2 Web.xml File in Struts 2.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Stateful Web Application Development with Spring Web Flow John Case Senior Consultant Centare Group, Ltd.
Struts 2.0 an Overview ( )
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.
INTRODUCTION TO WEB DATABASE PROGRAMMING
Java Server Pages CS-422. What are JSPs A logical evolution of java servlets –most servlets dynamically create HTML and integrate it with some computational.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
JSP Standard Tag Library
JavaServer Pages Syntax Harry Richard Erwin, PhD CSE301/CIT304.
4.1 JavaScript Introduction
PHP. Why should we learn web programming? No need write socket programming. - You can forget TCP/IP & OSI layers. - Web server handles socket tasks for.
16-1 The World Wide Web The Web An infrastructure of distributed information combined with software that uses networks as a vehicle to exchange that information.
JDeveloper 10g and JavaServer Faces: High-Performance UIs on the Web Avrom Roy-Faderman Senior Programmer May, 2006.
JavaScript Part 1.
JavaServer Faces Jeff Schmitt October 5, Introduction to JSF Presents a standard framework for building presentation tiers for web applications.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
® IBM Software Group © 2007 IBM Corporation JSP Expression Language
By: Saurabh Dixit.  Groovy server pages  Taglibs  Validators in grails.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
Website Development with PHP and MySQL Saving Data.
Introduction to JavaServer Pages. 2 JSP and Servlet Limitations of servlet  It’s inaccessible to non-programmers JSP is a complement to servlet  focuses.
Distributed Information Retrieval Using a Multi-Agent System and The Role of Logic Programming.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
JAVA SERVER FACES ADITI RAJORIYA UNI – ar2630. POINTS TO BE DISSCUSED WHAT IS JSF? WHY JSF? ARCHITECTURE JSF VERSIONS UI COMPONENTS JSF STRUCTURE AND.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Forms with Spring MVC Handling Form.
Jsp (Java Server Page) Is a server side program.
JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Struts 2 introduction. Struts 2 framework Struts 2 A full-featured web application framework for the Java EE platform The Java Servlet API exposes the.
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.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
JSP. Types of JSP Scripting Elements Expressions of the form, which are evaluated and inserted into the servlet's output. Scriptlets of the form, which.
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
©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.
Preface IIntroduction Objectives I-2 Course Overview I-3 1Oracle Application Development Framework Objectives 1-2 J2EE Platform 1-3 Benefits of the J2EE.
Implementation Struts Framework for well-architectured web applications Model-View-Controller design pattern.
JavaServer Faces framework Craig McClanahan is presented that created Struts web framework and based on experience gathered designed JavaServer.
Overview of Previous Lesson(s) Over View  ASP is a technology that enables scripts in web pages to be executed by an Internet server.  ASP.NET is a.
2006/2007 Licence Apache 2.0 Castle.Igloo. Castle Igloo Basics Pre-require Concept Scopes PageFlow Configuration Controller View Exemple Castle.Igloo.
Struts 2 Introduction.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Chapter 14 Using JavaBeans Components in JSP Documents.
Chapter 2 Java Struct 2. Content Basic MVC Architecture Struts 2 Overview Struts 2 - Architecture.
SDJ INFOSOFT PVT. LTD. 2 BROWSERBROWSER JSP JavaBean DB Req Res Application Layer Enterprise server/Data Sources.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Model View Controller. MVC is the separation of model, view and controller. It's simply a paradigm; an ideal that you should have in the back of your.
A first stab at a better templating system for Chisimba The Chisimba Canvas.
Struts 2 Development. Topics  Roles in Struts Development  Control Flow  Actions  Struts 2 Views and Target  Struts 2 Custom Tags  Validation 
Navigation Mimi Opkins CECS 493 Fall Static Navigation  In a simple web application, navigation is static. That is, clicking a particular button.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
“Under the hood”: Angry Birds Maze
Best Struts 2 Training By TOPS Technologies.
Struts 2 Validation Framework
Unit 6-Chapter 2 Struts.
Presentation transcript:

Data transfer and type conversion One of the common tasks of the web application domain was moving and converting data from string-based HTTP to the various data types of the Java language. Data transfer and type conversion actually happen on both ends of the request processing cycle. The framework moves the data from the string-based HTTP requests to our JavaBeans properties, which are clearly Java types. Moreover, the same thing happens on the other end. When the result is rendered, we typically funnel some of the data from those JavaBeans properties back out into the resulting HTML page.

OGNL and Struts 2 We need to understand how HTML request are mapped to the Java language and back out to HTML through the JSP tags. What OGNL does ? OGNL is quite ordinary. OGNL stands for the Object-Graph Navigation Language. OGNL is a powerful technology that’s been integrated into the Struts 2 framework to help with data transfer and type conversion. OGNL is the glue between the framework’s string-based HTTP input and output and the Java-based internal processing. OGNL consists of two things An expression language. Type converters.

OGNL and Struts 2 Expression Language OGNL’s expression language in our form input field attribute : name In both places, we’ve been using OGNL expressions to bind Java-side data properties to strings in the text- based view layers, commonly found in the name attributes of form input fields, or in various attributes of the Struts 2 tags. Example : The OGNL expression language is the bit inside the double quotes of the value attribute.

Expression Language OGNL creates the pathways for data to flow through the framework. It helps move data from the request parameters onto our action’s JavaBeans properties, and it helps move data from those properties out into rendering HTML pages. OGNL and Struts 2

Type Converters Every time data moves to or from the Java environment, a translation must occur between the string version of that data that resides in the HTML and the appropriate Java data type. The Struts 2 framework provides adequate built-in OGNL type converters. The built-in type converters and show you how to map your incoming form fields to a wide variety of Java data types, including all the primitives as well as a variety of collections. OGNL and Struts 2

How OGNL fits into the framework Figure 5.1 shows how OGNL has been incorporated into the Struts 2 framework. Figure 5.1 shows the path of data into and out of the framework. Everything starts with the HTML form in the InputForm.html page, from which the user will submit a request. Everything ends with the response that comes back to the user, represented in figure 5.1 as ResultPage.html.

Role of params interceptor Data in The params interceptor will move the data from the request object to the ValueStack. The tricky part of the job is mapping the name of the parameter to an actual property on the ValueStack. This is where OGNL comes in. The params interceptor interprets the request parameter name as an OGNL expression to locate the correct destination property on the ValueStack.

Role of ValueStack The ValueStack holds a stack of objects. These objects all have properties. If you look at this in figure 5.1, you might expect that the expression would need to be something more like myAction.user.username. To the contrary, only the user.username is necessary. This is because the ValueStack is a sort of virtual object that exposes the properties of its contained objects as its own.

DATA OUT When the result starts its rendering process, it’ll also have access to the ValueStack, via the OGNL expression language in its tags. These tags will retrieve data from the ValueStack by referencing specific values with OGNL expressions. In figure 5.1, the result is rendered by ResultPage.jsp. In this page, the age of the user is retrieved with the Struts 2 property tag, a tag that takes an OGNL expression to guide it to the value it should render. But, once again, we must convert the value; this time we convert from the Java type of the property on the ValueStack to a string that can be written into the HTML page. In this case, the Integer object is converted back into a string for the depressing message that “At 37, you’re our oldest user.” How OGNL fits into the framework

OGNL and Struts 2 Built-in type converters The Struts 2 framework comes with built-in support for converting between the HTTP native strings and the following list of Java types: String—Sometimes a string is just a string. boolean/Boolean—true and false strings can be converted to both primitive and object versions of Boolean. char/Character—Primitive or object. int/Integer, float/Float, long/Long, double/Double—Primitives or objects. Date—String version will be in SHORT format of current Locale (for example, 12/10/97). array—Each string element must be convertible to the array’s type. List—Populated with Strings by default. Map—Populated with Strings by default.

Mapping form field names to properties with OGNL expressions Hooking up your Java properties to your form field names to facilitate the automatic transfer and conversion of request parameters is a two-step process. First, you need to write the OGNL expressions for the name attributes of your form fields. Second, you need to create the properties that’ll receive the data on the Java side.

Mapping form field names to properties with OGNL expressions

The name is an OGNL expression. This expression is used to locate the target property on the ValueStack. In the case of the Register action, the action itself is on top of the stack and an OGNL expression such as user.birthday finds the user property on the action, then finds the birthday property on that user object. In Java, this becomes the following snippet: getUser().getBirthday();