Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

3) web development


Published on

  • Be the first to comment

  • Be the first to like this

3) web development

  1. 1. Vikas Manoria IT Specialist – IBM Academic Initiative [email_address] Section -3) Web Development
  2. 2. Section 3 - Web Development (20%) <ul><li>Create dynamic and static Web projects </li></ul><ul><li>Understand classpath and module dependencies </li></ul><ul><li>Use Page Designer to add and modify HTML, JavaScript, and JSP content </li></ul><ul><li>Configure Web project properties </li></ul><ul><li>Understand the available JSF (JavaServer Faces) development tools </li></ul><ul><li>Understand the available Struts development tools </li></ul><ul><li>Create and configure Servlets </li></ul>
  3. 3. The Key Views of the Web Perspective 1 4 2 3 5 7 6
  4. 4. Static Projects and Dynamic Projects <ul><li>A static Web project contains only static Web content, such as HTML pages, images, sounds, and movie files. </li></ul><ul><ul><li>These resources are designed to be deployed to a Web server, and do not require a J2EE application server. </li></ul></ul><ul><ul><li>The wizard allows you to select the CSS file for the project and it can build the static Web project from a template. </li></ul></ul><ul><li>A dynamic Web project contains resources needed for Web applications, such as JSPs, servlets, JavaBeans, and HTML </li></ul><ul><ul><li>You can specify the version of the servlet specification, target server containing EAR file, and context root within the wizard. </li></ul></ul>
  5. 5. Web Application - Static • Organizations want to make their information available to as many people in the world as possible. This can be achieved by using the Web, delivering the information as static HTML pages
  6. 6. Web Application Evolution - Servlets Applets cannot access data on back-end systems. A Web container can provide server-side components (such as Servlets) to generate dynamic content
  7. 7. Web Application Evolution - JSPs Servlets give poor separation between business logic and presentation logic. Use JavaServer Pages and JavaBeans to improve separation
  8. 8. MVC design pattern <ul><li>The Model </li></ul><ul><ul><li>Represents the underlying data and business logic in one place </li></ul></ul><ul><ul><li>Contains no information about the user interface </li></ul></ul><ul><li>The View </li></ul><ul><ul><li>The user interface – things the user can see and respond to </li></ul></ul><ul><ul><li>Represent a &quot;window&quot; into the model – there can be many of these </li></ul></ul><ul><li>The Controller </li></ul><ul><ul><li>Connects the model and the view </li></ul></ul><ul><ul><li>Used to communicate between the model and view </li></ul></ul><ul><li>MVC – M odel V iew C ontroller is a Design Pattern </li></ul><ul><ul><li>Very widely used and regarded as a core concept in J2EE development </li></ul></ul><ul><ul><li>Various practical benefits </li></ul></ul><ul><ul><ul><li>Promotes code reuse </li></ul></ul></ul><ul><ul><ul><li>Reduces development time </li></ul></ul></ul>
  9. 9. An Overview of the Web Resource Wizards <ul><li>All Web resources can be created with a wizard. </li></ul><ul><li>Web resources include: </li></ul><ul><ul><li>Projects </li></ul></ul><ul><ul><ul><li>Static, dynamic </li></ul></ul></ul><ul><ul><li>Java </li></ul></ul><ul><ul><ul><li>Servlet, filter, listener, bean </li></ul></ul></ul><ul><ul><li>View </li></ul></ul><ul><ul><ul><li>HTML, JSP, CSS, JavaScript, images </li></ul></ul></ul><ul><ul><li>Frameworks </li></ul></ul><ul><ul><ul><li>Struts, JavaServer Faces </li></ul></ul></ul><ul><ul><li>Visualization </li></ul></ul><ul><ul><ul><li>Web diagram </li></ul></ul></ul>
  10. 10. Dynamic Web Project Wizard (1 of 3) <ul><li>Specify </li></ul><ul><ul><li>Project name </li></ul></ul><ul><ul><li>Configuration </li></ul></ul><ul><ul><li>EAR Membership </li></ul></ul>
  11. 11. Dynamic Web Project Wizard (2 of 3) <ul><li>Choose Project Facets </li></ul><ul><ul><li>Adds functionality to a project </li></ul></ul><ul><ul><li>Manages project builders </li></ul></ul><ul><ul><li>Adds appropriate Jars, class files and other resources </li></ul></ul><ul><li>Configurations group facets </li></ul>
  12. 12. Dynamic Web Project Wizard (3 of 3) <ul><li>Set the Context Root </li></ul><ul><ul><li>http://hostname:port/ <contextRoot> /<resource> </li></ul></ul><ul><li>Content Directory </li></ul><ul><ul><li>Class files </li></ul></ul><ul><ul><li>Deployment descriptor </li></ul></ul><ul><ul><li>JSPs </li></ul></ul><ul><ul><li>Servlets </li></ul></ul><ul><ul><li>HTML </li></ul></ul><ul><ul><li>Other support files </li></ul></ul>
  13. 13. Page Templates <ul><li>You can use templates to provide a common look and feel </li></ul><ul><ul><li>They provide you with a base layout for a page </li></ul></ul><ul><ul><li>Changes to the look and feel of the template are reflected in pages that use that template </li></ul></ul><ul><ul><li>You can apply templates to individual pages, to groups of pages, or to an entire Web Site </li></ul></ul><ul><li>If you make changes to the page template, the pages created from that page template are automatically updated. You can create a page template in two ways: </li></ul><ul><ul><li>Create a brand new page template </li></ul></ul><ul><ul><li>Create a page template from an </li></ul></ul><ul><ul><li>existing Web page file </li></ul></ul><ul><li>There are two types of page templates </li></ul><ul><ul><li>Design-Time page templates </li></ul></ul><ul><ul><li>Dynamic page templates </li></ul></ul>
  14. 14. Design-Time and Dynamic Templates <ul><li>HTML and JavaServer pages can implement templates </li></ul><ul><li>Templates: </li></ul><ul><ul><li>Create a standard look and feel for your Web pages </li></ul></ul><ul><ul><li>Contain content areas that are filled in by the end Web Page </li></ul></ul><ul><ul><li>Separate content from layout </li></ul></ul><ul><li>Design-Time templates have the following characteristics: </li></ul><ul><ul><li>They can be used for both HTML and JSP pages </li></ul></ul><ul><ul><li>Pages are created immediately </li></ul></ul><ul><ul><li>Changes to the template update the Web pages </li></ul></ul><ul><ul><li>Templates can be nested </li></ul></ul><ul><li>Dynamic templates: </li></ul><ul><ul><li>Leverage Struts-Tiles technology </li></ul></ul><ul><ul><li>Can only be used with JSPs </li></ul></ul><ul><ul><li>Generate pages during run time </li></ul></ul>Content Area Nav Bar Header
  15. 15. The Structure of a Web Project <ul><li>The J2EE model defines a Web application directory structure that specifies the location of Web content files, class files, class paths, deployment descriptors, and supporting metadata. </li></ul><ul><li>Rational Application Developer mirrors this model in its directory structure. </li></ul>
  16. 16. The WebContent Folder <ul><li>This folder contains items to be published to the server </li></ul><ul><li>This is the root level for all content that is published </li></ul><ul><ul><li>The context root should point to this folder </li></ul></ul><ul><li>It includes three sub-folders: </li></ul><ul><ul><li>META-INF, theme, and WEB-INF </li></ul></ul>http://myServer:port/Library/Register.jsp
  17. 17. The WEB-INF Folder <ul><li>This is the location for all protected resources. </li></ul><ul><li>Files in this folder cannot be called directly from a browser. </li></ul><ul><ul><li>They would be invoked from another file </li></ul></ul><ul><li>The folder stores supporting Web resources: </li></ul><ul><ul><li>Java .class files </li></ul></ul><ul><ul><li>Libraries </li></ul></ul><ul><ul><li>The deployment descriptor </li></ul></ul><ul><ul><li>.xmi files </li></ul></ul><ul><ul><li>.xml files </li></ul></ul>
  18. 18. Navigating the Deployment Descriptor (1 of 2) <ul><li>The deployment descriptor file (web.xml) is in the WEB-INF folder, but there is a shortcut to open the editor easily. </li></ul><ul><li>It is recommended that you use the tabbed pages to construct the deployment descriptor for your Web application. </li></ul>
  19. 19. Navigating the Deployment Descriptor (2 of 2) <ul><li>You can enter information either through the UI interface (the tabs), or directly in the XML source code </li></ul><ul><ul><li>Changes in one will be reflected in the other </li></ul></ul>
  20. 20. Organize Web Pages in a Site Hierarchy <ul><li>Web sites organize pages in a hierarchy </li></ul><ul><li>The Web Site Designer is an editor that allows you to design and maintain the site hierarchy </li></ul><ul><ul><li>Graphically design the navigation between Web pages </li></ul></ul><ul><ul><li>Apply a common stylesheet and page template to Web pages </li></ul></ul><ul><ul><li>Generate and automatically update navigation links and a site map page </li></ul></ul><ul><li>Open the Web Site Designer by opening the Web Site Navigation link in the Web project </li></ul>
  21. 21. Web Site Navigation Overview 1 2 4 5 3
  22. 22. Relationship between Web Site Pages <ul><li>Lines between page icons denote a relationship </li></ul><ul><ul><li>For example, the index page is the parent of the product and feedback Web pages </li></ul></ul><ul><li>Pages on the same level have a peer relationship </li></ul><ul><li>Dashed lines around a page icon denotes a page that has been added to the site hierarchy but not yet created </li></ul><ul><ul><li>Realize the Web page by selecting Create Page from the pop-up menu </li></ul></ul><ul><li>You can also share pages to create clones that can be placed in the editor </li></ul><ul><ul><li>For example a shared Help or Contact page </li></ul></ul>
  23. 23. Relationship with External Links <ul><li>External links are links with Web pages in other Web projects or other servers </li></ul><ul><li>Use the External Links item in the Palette view to add the following types of links: </li></ul><ul><ul><li>File </li></ul></ul><ul><ul><ul><li>A Web page in the workspace </li></ul></ul></ul><ul><ul><li>HTTP </li></ul></ul><ul><ul><ul><li>A Web page address </li></ul></ul></ul><ul><ul><li>FTP </li></ul></ul><ul><ul><ul><li>An FTP site address </li></ul></ul></ul><ul><ul><li>E-mail </li></ul></ul><ul><ul><ul><li>A mailto link to send e-mail </li></ul></ul></ul><ul><ul><li>Other </li></ul></ul><ul><ul><ul><li>A URL address over any protocol </li></ul></ul></ul>Icon represents an external link in the Web Site Navigation
  24. 24. Group Logical Set of Web Pages <ul><li>Group Web pages to: </li></ul><ul><ul><li>Create a logical organization </li></ul></ul><ul><ul><ul><li>Group a branch of the site hierarchy according to category </li></ul></ul></ul><ul><ul><li>Create a reoccurring set of links, such as header or footer </li></ul></ul><ul><ul><ul><li>Group a set of links that appears on more than one page but have no relationship to each other </li></ul></ul></ul><ul><li>To create a group, select a set of Web </li></ul><ul><li>pages and use the Group command </li></ul>
  25. 25. Web Site Details Overview 1 2 3 4 5
  26. 26. Add Navigation Elements to Web Pages (1 of 2) <ul><li>In the Palette view, use the Web Site Navigation drawer to add navigation elements to a Web page </li></ul><ul><ul><li>Horizontal/Vertical Bar : Adds a row or column of links </li></ul></ul><ul><ul><li>Horizontal/Vertical Tabs : Adds a row or column of tabs </li></ul></ul><ul><ul><li>Horizontal/Vertical menu : Standard menu </li></ul></ul><ul><ul><li>Tabbed menu : Uses tabs to contain the hierarchy </li></ul></ul><ul><ul><li>Navigation Trail : Writes out the path to the current page </li></ul></ul><ul><ul><li>Drop-Down list : Displays a combo-box </li></ul></ul><ul><ul><li>Site Map : Creates a table of links in the current page </li></ul></ul><ul><li>The best practice is to add the navigation elements to a template </li></ul>
  27. 27. Add Navigation Elements to Web Pages (2 of 2)
  28. 28. Add Web Pages to the Web Diagram <ul><li>Select a Web page in the Web Site Designer. </li></ul><ul><li>Open the pop-up menu, right-click and select Show Page in Web Diagram Editor . </li></ul><ul><li>Conversely, you can select a Web page in the Web Diagram Editor and select Show Page in the Web Site Designer . </li></ul>
  29. 29. Add Web Page Links in the Web Diagram <ul><li>There are different ways to create links: </li></ul><ul><ul><li>From the Palette view, select the Connection item, click the first page and drag the connection to the second page. </li></ul></ul><ul><ul><li>Drag the connection handle to another page or an empty space to create the end page. </li></ul></ul><ul><ul><li>From the fly out, choose a type of link and then drag its connection handle to a page. </li></ul></ul>1 2 3
  30. 30. The New Web Page Wizard: HTML/XHTML Template <ul><li>The folder must exist before the file can be created </li></ul><ul><ul><li>Browse to a legitimate location </li></ul></ul><ul><li>Choose a markup language </li></ul><ul><ul><li>HTML is the default </li></ul></ul>
  31. 31. The JSP Wizard <ul><li>The file can be standard JSP or Fragment </li></ul><ul><li>If the Dynamic Web Project has a Faces or Struts Facet added to it, the Wizard Options dialog will enable a Faces or Struts JSP to be created </li></ul>
  32. 32. The Page Designer Editor <ul><li>Page Designer is an HTML and JSP editor for developing Web pages both visually and textually </li></ul><ul><ul><li>Including form elements, Java applets, embedded scripts, and JSP tags </li></ul></ul><ul><li>Three modes: Design, Source, and Preview </li></ul><ul><li>Content assist is available in the Source page for HTML, JSP, and JavaScript </li></ul><ul><ul><li>The type of assistance is set automatically according to the position of the cursor, type of page, and page contents (such as included taglibs) </li></ul></ul>
  33. 33. JSP Architecture <ul><li>JSP Source Code runs on the Web server in the JSP Servlet Engine </li></ul><ul><li>The JSP Servlet Engine dynamically generates the HTML and send the output to the client. </li></ul><ul><li>A JSP takes the same path as the “Servlet Life Cycle” </li></ul>
  34. 34. Adding Tags Using the Palette View <ul><li>The Palette view contains a series of drawers. Each drawer contains items that can be dragged into the active editor. </li></ul><ul><li>The Palette view can be customized </li></ul><ul><ul><li>Right-click within the Palette view and select Customize </li></ul></ul>
  35. 35. Using the Insert Menu <ul><li>HTML elements can be inserted in the Design </li></ul><ul><li>The element may not be visible </li></ul><ul><ul><li>There may be just an icon to mark the place </li></ul></ul><ul><li>The area of the element may be outlined for design-time convenience </li></ul><ul><ul><li>Forms, tables </li></ul></ul>
  36. 36. Inserting JSP Code in the Page Designer <ul><li>If a JSP file is active in the editor, an additional menu appears </li></ul><ul><li>JSP tags can be inserted in either the Design view or the Source view </li></ul><ul><ul><li>For expressions, scriptlets, and declarations, a tag icon is inserted in the Design view, but Content-assisted coding can only be done in the Source view </li></ul></ul>
  37. 37. Inserting JSP Custom Tags <ul><li>Using the JSP menu, you can insert custom tags from any custom tag libraries imported in the JSP </li></ul><ul><ul><li>Select JSP > Insert Custom from the menus to open the Insert Custom Tag dialog </li></ul></ul><ul><ul><li>Select the appropriate tag library, then the custom tag, and select Insert </li></ul></ul>
  38. 38. Modifying Tag Properties in the Properties View <ul><li>The Properties view displays names and basic properties of a selected resource. </li></ul><ul><li>The view can be toggled between graphic and tabular presentation. </li></ul>
  39. 39. Adding Variables to the Page Data View <ul><li>The Page Data view allows you to manage data from a variety of sources </li></ul><ul><li>Data is added to the view </li></ul><ul><ul><li>Scripting variables, session EJBs, JavaBeans, Web services, and so on </li></ul></ul><ul><li>The data can then be configured and dragged onto a JSP </li></ul>
  40. 40. Editing JavaScript in the Quick Edit View <ul><li>The Quick Edit view is used to add short scripts to HTML and JSP files. </li></ul><ul><ul><li>For example, select a button tag on a JSP page, associate a click event with that button and add a script to it. </li></ul></ul><ul><li>You can drag items from the Snippets view into the Quick Edit view. </li></ul>
  41. 41. The Cascading StyleSheet Wizard <ul><li>Style sheets define a consistent look and feel throughout a Web site. </li></ul><ul><ul><li>Very important to a well-managed dynamic or static Web site </li></ul></ul><ul><li>Contents (Web pages) and design (the style sheet) are maintained separately. </li></ul><ul><ul><li>Facilitate separation of presentation from content </li></ul></ul><ul><li>CSS files should be under the Web content folder of the Web project. </li></ul><ul><ul><li>Rational Application Developer creates a theme folder for CSS files. </li></ul></ul>
  42. 42. Editing CSS Files in the CSS Designer <ul><li>CSS Designer shows the source of a style sheet and helps to edit styles by using syntax highlighting, content assist, and a preview function. </li></ul><ul><li>Modifications you make in CSS Designer are immediately applied to the Design page of Page Designer. </li></ul>
  43. 43. Using the Links View <ul><li>The Links view shows all links to and from a page. </li></ul><ul><li>It presents the number of links to target files and indicates where documents have broken links or links to external files. </li></ul><ul><li>This view is good both to see the flow of a Web site and to check the status of the links between resources. </li></ul>
  44. 44. Configuring Pages in the Deployment Descriptor <ul><li>Welcome and Error page lists can be configured. </li></ul><ul><li>The Welcome page is selected if a user does not indicate a particular page: </li></ul><ul><ul><li> </li></ul></ul><ul><li>Error pages are </li></ul><ul><li>displayed in </li></ul><ul><li>response to </li></ul><ul><li>specific HTTP </li></ul><ul><li>error codes </li></ul>
  45. 45. What is a Servlet ? <ul><li>Servlets are programs that run on a web server and build web pages dynamically </li></ul><ul><li>Servlets run on server to accept request and send back the response </li></ul><ul><li>Servlets are Platform and Server independent </li></ul><ul><li>Servlets have access to the entire family of Java API’s ( JDBC, HTTP etc..) </li></ul>“ A Servlet is a Web component, managed by a container, that generates dynamic content. Servlets are small, platform-independent Java classes compiled to an architecture-neutral byte code that can be loaded dynamically into and run by a Web server”
  46. 46. Steps to Create a New Servlet <ul><li>In a dynamic Web project, to create a new servlet: </li></ul><ul><ul><li>Use the Create Servlet wizard. </li></ul></ul><ul><ul><ul><li>In the Web perspective, select File > New > Other . </li></ul></ul></ul><ul><ul><ul><li>Select Web > Servlet from the New wizard. </li></ul></ul></ul><ul><ul><li>Use the Add servlet button in the Web deployment descriptor. </li></ul></ul><ul><ul><ul><li>Open Project Navigator > Web Application > Web Deployment Descriptor . </li></ul></ul></ul><ul><ul><ul><li>Select the Servlets tab to reveal the Servlets in the current Web project. </li></ul></ul></ul><ul><ul><ul><li>Click Add under the list of Servlets and JSPs. </li></ul></ul></ul>
  47. 47. <ul><li>The first page of the Create Servlet wizard specifies the class file location and information. </li></ul><ul><ul><li>Select the Web Project. </li></ul></ul><ul><ul><li>Specify the location folder for the Java source file. </li></ul></ul><ul><ul><li>Declare the package to which the new servlet belongs. </li></ul></ul><ul><ul><li>Set the class name for the servlet. </li></ul></ul><ul><ul><li>Define the superclass for the servlet. </li></ul></ul><ul><ul><li>Select Use existing Servlet class to reference an existing Java servlet class. </li></ul></ul><ul><ul><li>Select Generate an annotated servlet class to use XDoclet tags in the new servlet. </li></ul></ul>Create Servlet Wizard (1 of 3) 1 4 6 3 2 5 7
  48. 48. Create Servlet Wizard (2 of 3) <ul><li>The second page of the Create Servlet wizard defines what packages and classes to generate for the servlet. </li></ul><ul><ul><li>Define the servlet name and description for the Web deployment descriptor. </li></ul></ul><ul><ul><li>Add initialization parameters name and values. </li></ul></ul><ul><ul><li>Add additional URL mappings for the servlet. </li></ul></ul><ul><ul><li>Click Next to add method stubs, or click Finish to create the servlet class. </li></ul></ul>9 10 11 8
  49. 49. Create Servlet Wizard (3 of 3) <ul><li>Set modifiers, interfaces to implement and method stubs to create. </li></ul><ul><ul><li>Configure the servlet class access modifiers . </li></ul></ul><ul><ul><li>Implement additional interfaces in the servlet class. </li></ul></ul><ul><ul><li>Select Constructors from superclass check box to create stubs for constructors defined in the superclass. </li></ul></ul><ul><ul><li>Select the Inherited abstract methods check box to create a stub from abstract methods. </li></ul></ul><ul><ul><li>Create method stubs found in the HTTP servlet class. </li></ul></ul><ul><ul><li>Click Finish to generate the servlet. </li></ul></ul>12 14 13 15 16 17
  50. 50. Servlets in the Web Project <ul><li>Servlets appear in three locations within the Web project: </li></ul><ul><ul><li>Deployment Descriptor </li></ul></ul><ul><ul><ul><li>In the hierarchical view of the web.xml file contents, the servlet appears under the Servlets branch </li></ul></ul></ul><ul><ul><li>Java Resources </li></ul></ul><ul><ul><ul><li>The JavaSource folder holds all Java source files in the Web project, including servlets </li></ul></ul></ul><ul><ul><li>WebContent </li></ul></ul><ul><ul><ul><li>Stores compiled Java classes, including servlets, in the WEB-INF/classes sub-folder </li></ul></ul></ul><ul><ul><ul><li>Stores supporting JAR files in the WEB-INF/lib sub-folder </li></ul></ul></ul>1 3 2
  51. 51. Web Deployment Descriptor Servlet Settings 1 4 3 2 5
  52. 52. Servlet Settings Source Editor
  53. 53. What Is Struts? <ul><li>An open-source framework for implementing Web applications based on Java and J2EE </li></ul><ul><li>The framework was originally developed by C. McClanahan </li></ul><ul><ul><li>Technical lead for the Servlet and JSP reference implementation at Sun Microsystems </li></ul></ul><ul><li>Rational Application Developer V7 supports Struts 1.1 </li></ul><ul><li>Struts 2.0.9 was released in July 2007 </li></ul><ul><ul><li>Struts 2 was originally known as WebWork 2. </li></ul></ul><ul><ul><li>The WebWork and Struts communities joined forces to create Struts 2. </li></ul></ul><ul><ul><li>Key features include: </li></ul></ul><ul><ul><ul><li>AJAX support </li></ul></ul></ul><ul><ul><ul><li>Spring integration </li></ul></ul></ul><ul><ul><ul><li>POJO Forms and POJO Actions </li></ul></ul></ul><ul><ul><li>Requires Servlet API 2.4, JSP 2.0, and Java 5 or later . </li></ul></ul>
  54. 54. Struts is an MVC Framework <ul><li>The Struts architecture encourages the implementation of the concepts of the model-view-controller (MVC) architecture pattern. </li></ul><ul><li>The Struts framework is only concerned with the View-Controller part of MVC. </li></ul>Controller View Configuration files (XML) Model Data Store request response Struts framework
  55. 55. Extensions to the Basic Struts Framework <ul><li>Tiles </li></ul><ul><ul><li>Build Web pages from several discrete fragments </li></ul></ul><ul><ul><ul><li>Similar to portlets </li></ul></ul></ul><ul><ul><li>Each fragment can be reused where needed throughout applications </li></ul></ul><ul><li>Validation </li></ul><ul><ul><li>The Struts Validator plug-in provides a large number of basic validation rules that can be used with Struts. For example: </li></ul></ul><ul><ul><ul><li>minlength (maxlength) : Check that input data is not less than (greater than) a specified length </li></ul></ul></ul><ul><ul><ul><li>mask : Validate format according to a regular expression </li></ul></ul></ul><ul><ul><ul><li>double : Verify that a field can be converted to a Double </li></ul></ul></ul>
  56. 56. Creating Struts Components Using Wizards <ul><ul><li>The Struts framework provides a default ActionServlet and RequestProcessor that can be used in most cases </li></ul></ul><ul><ul><ul><li>Developers can subclass RequestProcessor and override the methods to create a custom RequestProcessor </li></ul></ul></ul>ActionServlet JSP Persistence Resource Bundle RequestProcessor ActionForm Tiles struts-config.xml Action Beans
  57. 57. A Struts-Enabled Project <ul><li>A dynamic Web project can be Struts-enabled: </li></ul><ul><ul><li>At creation time </li></ul></ul><ul><ul><li>Through the properties dialog </li></ul></ul>
  58. 58. Creating Struts Modules <ul><li>A Struts project can be divided into modules </li></ul><ul><ul><li>A Struts Module consists of a configuration file and a set of corresponding actions, form beans, and Web pages. </li></ul></ul><ul><li>Each module has its own configuration file </li></ul><ul><ul><li>This allows multiple users to work on the same project simultaneously, without the risk of overwriting the configurations. </li></ul></ul><ul><li>A default module is created with the Struts project </li></ul><ul><ul><li>The configuration file is called struts-config.xml. </li></ul></ul>
  59. 59. Associating Struts Modules with a Project <ul><li>A module’s configuration file is associated with a project in the project deployment descriptor (web.xml) </li></ul><ul><li>The first module created in a Struts-based Web application has no module name and is the default module </li></ul><ul><ul><li>The default module has one or more configuration files. </li></ul></ul><ul><ul><li>Each additional module has a name and exactly one configuration file. </li></ul></ul><init-param> <param-name>config</param-name> <param-value> /WEB-INF/struts-config.xml </param-value> </init-param> <init-param> <param-name> config/NewModule </param-name> <param-value> /WEB-INF/struts-NewModule.xml </param-value> </init-param>
  60. 60. Mapping Struts Applications with Web Diagrams
  61. 61. Examining Struts Resources <ul><li>Resources can be examined in the Project Explorer </li></ul>
  62. 62. Examining the Struts Configuration File <ul><li>There may be several configuration files </li></ul><ul><ul><li>The default module may have several </li></ul></ul><ul><ul><li>There may be several modules, each with a configuration file </li></ul></ul><ul><li>The files are contained in the WebContent/WEB-INF folder </li></ul><init-param> <param-name>config</param-name> <param-value>/WEB-INF/ struts-config.xml </param-value> </init-param> <init-param> <param-name>config/Account</param-name> <param-value>/WEB-INF/ struts-Account.xml </param-value> </init-param> <init-param> <param-name>config/Customer</param-name> <param-value>/WEB-INF/ struts-Customer.xml </param-value> </init-param>
  63. 63. A Closer Look at the <action-mappings> Tag <ul><li><action-mappings> </li></ul><ul><li> <action name=&quot;loginForm&quot; path=&quot;/login&quot; scope=&quot;request&quot; </li></ul><ul><li> type=&quot;; </li></ul><ul><li> input=&quot;/index.jsp&quot;> </li></ul><ul><li><forward name=&quot;failure&quot; path=&quot;/error.jsp&quot;></forward> </li></ul><ul><li><forward name=&quot;success&quot; path=&quot;/home.jsp&quot;></forward> </li></ul><ul><li> </action> </li></ul><ul><li></action-mappings> </li></ul>index.jsp LoginForm ActionErrors validate(args) Validation OK? NO | YES LoginAction 1 2 3 4 5 6 error.jsp home.jsp … / 1 2 3 4 6 5
  64. 64. What Is JavaServer Faces Technology? <ul><li>JavaServer Faces (JSF) technology is a user interface framework for developing Web-based applications: </li></ul><ul><ul><li>Provides a rich library of user interface (UI) components </li></ul></ul><ul><ul><li>Abstracts request processing in an event-driven model </li></ul></ul><ul><ul><li>Contains declarative rules to define the Web application page flow </li></ul></ul><ul><ul><li>Helps you manage session data by initializing, persisting, and cleaning up model data objects </li></ul></ul><ul><ul><li>Allows binding of reusable data validators to UI components </li></ul></ul><ul><ul><li>Supports internationalization through locale-specific text, number, currency, time, and date formatting </li></ul></ul><ul><li>A JSF application is a Web application, as defined in the J2EE specification </li></ul><ul><li>WebSphere Application Server v6.1 and later supports JSF 1.1 </li></ul>
  65. 65. Parts of a JSF Application IBM WebSphere Application Server J2EE Enterprise Application JSF Web Application Faces Configuration File Faces Servlet Faces JSP File Component Tree Web Client Managed Beans JSF Libraries/Tags Validators Events
  66. 66. JSF Development Steps <ul><li>Create a Dynamic Web Project with JSF support </li></ul><ul><li>Create a Faces JSP File </li></ul><ul><li>Add data components to your Faces JSP file using the Page Data view </li></ul><ul><li>Add JSF user interface components to the page to collect and display data </li></ul><ul><li>Configure the properties for each JSF UI component using the Properties view </li></ul><ul><li>Specify navigation rules driven by result from event handler code </li></ul><ul><li>Add event handler code to react to user interface events </li></ul><ul><li>Test and Debug the JSF application using the WebSphere Test Environment </li></ul>
  67. 67. Create a Dynamic Web Project <ul><li>Switch to the Web perspective </li></ul><ul><li>Select File > New > Dynamic Web Project </li></ul><ul><ul><li>Enter a Project name </li></ul></ul><ul><ul><li>Select Faces Project in the Configurations list </li></ul></ul><ul><ul><li>Click Finish </li></ul></ul>
  68. 68. Create a Faces JSP File <ul><li>Right-click the Web project and select New > Web Page </li></ul><ul><ul><li>Once the Faces facet is added to the project, new Web pages will use Faces technology </li></ul></ul><ul><li>Specify a File Name and Folder </li></ul><ul><li>Click Options for more settings </li></ul>
  69. 69. Add Data Components to the Page Data View <ul><li>Types of Page Data objects: </li></ul><ul><ul><li>Scripting Variables </li></ul></ul><ul><ul><ul><li>Variables available to JSP file </li></ul></ul></ul><ul><ul><li>PageBean </li></ul></ul><ul><ul><ul><li>Local bean that can be bound to data fields </li></ul></ul></ul><ul><ul><li>Faces Managed Beans </li></ul></ul><ul><ul><ul><li>A bean that is available to all Faces pages </li></ul></ul></ul><ul><ul><li>Relational Record and Record List </li></ul></ul><ul><ul><ul><li>Displays a record or a list of records from a relational database </li></ul></ul></ul><ul><ul><li>Domino </li></ul></ul><ul><ul><ul><li>Domino Note, View </li></ul></ul></ul><ul><ul><li>Service </li></ul></ul><ul><ul><ul><li>EJB Session bean, SDO, Web Service </li></ul></ul></ul>
  70. 70. Bind Page Data to Faces Components <ul><li>Create a value binding between a Page Data object and a Faces component to display or modify its value </li></ul><ul><ul><li>Add a Faces component to the JSP file </li></ul></ul><ul><ul><li>Select a data object from the Page Data view </li></ul></ul><ul><ul><li>Select the Faces component to bind the data object with the Faces component </li></ul></ul>
  71. 71. Add UI Components to a Faces JSF File 1 3 2 4 5
  72. 72. Standard Faces Components <ul><li>Data Table displays and manipulates data in a dynamic table </li></ul><ul><li>Command - Button runs an action </li></ul><ul><li>Link adds a simple hyperlink </li></ul><ul><li>Input creates a form input field </li></ul><ul><li>Input - Text Area creates a multi-line form input field </li></ul><ul><li>Input - Password creates a form input field that hides the input </li></ul><ul><li>Check Box and Check Box group </li></ul><ul><li>Radio Button Group </li></ul><ul><li>Combo Box </li></ul><ul><li>List Box – single and multiple select </li></ul><ul><li>Output displays text or a value from a Java bean </li></ul><ul><li>Output - Formatted Text displays a set of concatenated values </li></ul><ul><li>Image displays an image </li></ul><ul><li>Label displays an accessibility label </li></ul><ul><li>Display Error shows an error message </li></ul><ul><li>Display Errors shows all error messages in the page </li></ul>
  73. 73. Enhanced Faces Components <ul><li>Data tree displays data in a hierarchy </li></ul><ul><li>Panel – Group Box groups components </li></ul><ul><li>Panel – Form Box organizes components in label and field pairs </li></ul><ul><li>Panel – Dialog behaves like a model or modeless dialog </li></ul><ul><li>Panels – Tabbed organizes panels in tabs </li></ul><ul><li>Link – Request passes an action via the URL </li></ul><ul><li>Form Item – inserts a label / field pair for a form </li></ul><ul><li>Select – Color selects a color with a combo box </li></ul><ul><li>Select – Calendar displays a selectable calendar </li></ul><ul><li>File Upload , Chart , Progress Bar </li></ul><ul><li>Media Player inserts different players </li></ul>
  74. 74. Map JSF Components in Web Diagrams <ul><li>Use the Web Diagram to visually design Faces JSF files, Faces Actions, and navigation rules </li></ul><ul><li>Web Diagram can reverse-engineer individual pages or the entire project </li></ul><ul><li>Use the palette to create new Web projects, Web pages, and actions </li></ul><ul><ul><li>Then create connections between them </li></ul></ul>
  75. 75. Code Event Handlers in the Quick Edit View <ul><li>The Quick Edit view allows you to code the client-side and server-side event logic for JSF components </li></ul><ul><li>To modify the event logic for a JSF component: </li></ul><ul><ul><li>Select the JSF component in the Page Designer </li></ul></ul><ul><ul><li>Locate the Quick Edit view, and select the type of event you will handle </li></ul></ul><ul><ul><li>Enter JavaScript code for client-side events, and Java code for server-side events </li></ul></ul>
  76. 76. JSF Application Organization and Artifacts 1 2 3 4 5
  77. 77. Multiple Faces-config Files <ul><li>Artifacts can be organized into multiple configuration files </li></ul><ul><li>Individual artifact types can be organized into a folder hierarchy </li></ul>
  78. 78. JSF Pages and the Page Code Class <ul><li>Each Faces JSP file that you create usually has a corresponding file that contains its Java page code </li></ul><ul><ul><li>You can create Page code classes in Java Resources  JavaSource  pagecode </li></ul></ul><ul><li>Server-side event logic added to a JSF component in the Quick Edit view is added to the page code class </li></ul><ul><ul><li>Page code event logic can be modified from this view later </li></ul></ul>JSF Web Application Persistence Faces JSP File beans Page Code Class Events
  79. 79. Page Code Class Suppression <ul><li>To suppress page code generation </li></ul><ul><ul><li>Before you create a Web page, select Windows > Preferences > Web Tools > Faces from the main menu </li></ul></ul><ul><ul><li>Select the Suppress Page Code file generation </li></ul></ul><ul><ul><li>New Web pages will no longer have an associated page code class </li></ul></ul><ul><li>A page code is required to support </li></ul><ul><ul><li>A relational record </li></ul></ul><ul><ul><li>A relational record list </li></ul></ul><ul><li>If page code is suppressed, Quick Edit will no longer have a Command entry for a Command button </li></ul>
  80. 80. Checkpoint <ul><li>Describe two of the views of the Web perspective. </li></ul><ul><li>What is the principal difference between a static and a dynamic Web project? </li></ul><ul><li>What is a context root? </li></ul><ul><li>Name two of the project facets that you can add when you create a new Web project. </li></ul><ul><li>What is a validator? </li></ul><ul><li>What folders are contained in the WebContent folder? </li></ul>
  81. 81. Checkpoint answers <ul><li>See page 3, students notes. </li></ul><ul><li>A static Web project contains only static Web content. A dynamic Web project contains resources needed for Web applications, such as JSPs and Java Servlets. </li></ul><ul><li>A context root is the default relative path to the Web content from the server root when a Web project is published. </li></ul><ul><li>Base JSF Faces support, Tiles 1.1 support, Struts support, Web diagram, JSP Tag libraries, Crystal reports. </li></ul><ul><li>A program that checks data or code for correctness or for compliance with applicable standards, rules, and conventions. </li></ul><ul><li>META-INF, theme, WEB-INF, and any folders defined in the project </li></ul>
  82. 82. Checkpoint <ul><li>In the Web Site Designer, how do you specify a set of links that have no relation to each other but appear on multiple pages? </li></ul><ul><li>The Pages to Add drawer lists all Web pages in the Web project that have not been added to the Web Site Navigation. Where is this list located? </li></ul><ul><li>What is the best practice for adding Web Site Navigation elements into a Web site? </li></ul><ul><li>What is an external link in the Web Site Designer? </li></ul>
  83. 83. Checkpoint answers <ul><li>Right-click the Web page icons and Group them. </li></ul><ul><li>The Pages to Add drawer is located on the left edge of the Web Site Designer editor in the Navigation tab. </li></ul><ul><li>The best practice is to add the navigation links to the templates that the pages implement. </li></ul><ul><li>An external link is a hyperlink to a Web resource outside of the Web project. </li></ul>
  84. 84. Checkpoint <ul><li>In general, what are two ways to invoke the wizard to create a servlet, a filter, or a life-cycle listener? </li></ul><ul><li>How do you ensure that the workbench does not overwrite your custom Web deployment descriptor settings with annotations within the Java source? </li></ul><ul><li>Regarding URL mappings and servlet mappings: </li></ul><ul><ul><li>What is the difference between the two types of mappings? </li></ul></ul><ul><ul><li>When you create a new filter, where can you set a URL mapping or a servlet mapping? </li></ul></ul>
  85. 85. Checkpoint answers <ul><li>The two ways to invoke any new Web resource wizard is to use the New wizard dialog by selecting File  New  Other, or clicking add in the respective section in the Web deployment descriptor. </li></ul><ul><li>To prevent the workbench from overwriting the Web deployment descriptor settings with annotations in the servlet class, add the @annotations-disabled tagset=”web” tag to the servlet class. The workbench will ask whether you want to have the tag inserted into the servlet class if you modify the settings in the Web deployment descriptor editor. </li></ul><ul><li>Regarding URL mappings and servlet mapping in filters: </li></ul><ul><ul><li>URL mappings checks using a text comparison whether the incoming HTTP request triggers a filter. Servlet mappings links the name of a servlet to a filter. Using servlet mappings ensures that the container invokes the filter, even if the URL mapping for the servlet changes. Using URL mappings allows you to map the filter to more than one servlet per entry. </li></ul></ul><ul><ul><li>You can add an URL mapping in the Create Filter wizard or in the Filters tab in the Web deployment descriptor editor. However, you can only add a servlet mapping through the Web deployment descriptor editor. </li></ul></ul>
  86. 86. Checkpoint <ul><li>What is Struts? </li></ul><ul><li>Struts is involved in which parts of the MVC architecture? </li></ul><ul><li>Name an extension to the Struts framework. </li></ul><ul><li>Which are the controller components in Struts? </li></ul><ul><li>How many configuration files are there in a Struts project? </li></ul><ul><li>Which versions of Struts are supported by Rational Application Developer? </li></ul><ul><li>In the following code, what is the purpose of the input attribute? </li></ul><ul><li><action name=&quot;loginForm&quot; path=&quot;/login&quot; </li></ul><ul><li> scope=&quot;request&quot; </li></ul><ul><li> type=&quot;; </li></ul><ul><li> input=&quot;/welcome.jsp&quot;> </li></ul>
  87. 87. Checkpoint answers <ul><li>Struts is an open-source framework for implementing Web applications based on Java and J2EE. </li></ul><ul><li>The Struts framework is only concerned with the View-Controller part of MVC. </li></ul><ul><li>Tiles and Validation. </li></ul><ul><li>Controller layer is implemented using: </li></ul><ul><ul><li>ActionServlet </li></ul></ul><ul><ul><li>Struts configuration file (struts-config.xml) </li></ul></ul><ul><ul><li>RequestProcessor </li></ul></ul><ul><ul><li>Action classes </li></ul></ul><ul><ul><li>ActionForward classes </li></ul></ul><ul><li>Depends upon the number of modules. If you have only one module, then there is only configuration file struts-config.xml </li></ul><ul><li>Struts 1.1 </li></ul><ul><li>The page that will be returned to the browser if validation fails in the ActionForm. </li></ul>
  88. 88. Checkpoint <ul><li>How does the Page Data view help you develop your Faces JSP file? </li></ul><ul><li>Which JSF component allows you to prompt the user about an invalid username field in a login page? </li></ul><ul><li>Without manually editing the Faces configuration file, how can you add new navigation rules to your JSF application? </li></ul><ul><li>What is the purpose of using the Quick Edit view on JSF UI components? </li></ul>
  89. 89. Checkpoint answers <ul><li>The Page Data view displays the data components with which your Faces JSP file interacts. In normal JSP pages, you must manually add a bean into a request, session, page, or application scope. The name and type of the object does not appear in the Page designer or any of its views. With JSF technology, the Page Data view displays objects managed by the framework in one of the available scopes. The Page designer also understands any object dragged from the Page Data view into the Page designer. </li></ul><ul><li>The Display Error JSF UI Component is best suited to return a single error message about an invalid username in a Faces JSF login page. The Display Errors component is designed to return multiple errors. </li></ul><ul><li>You can add JavaServer Faces navigation rules by visually drawing them out in a Web diagram. </li></ul><ul><li>Developers would use the Quick Edit view to implement the event handling code behind a JSF UI component event, such as a mouse click. </li></ul>
  90. 90. Lab <ul><li>Create Static Web Project </li></ul><ul><li>HTML/XHTML Editor </li></ul><ul><li>Quick Edit & Properties </li></ul><ul><li>Create Dynamic Web Project </li></ul><ul><li>Website Navigation / Web Diagram </li></ul><ul><li>Deployment Descriptor </li></ul><ul><li>JSP Editor </li></ul><ul><li>Create Servlet </li></ul><ul><li>Struts </li></ul><ul><li>Java Server Faces </li></ul><ul><li>JSF Components </li></ul>
  91. 91. Japanese Hebrew Thank You English Merci French Russian Danke German Grazie Italian Gracias Spanish Obrigado Portuguese Arabic Simplified Chinese Traditional Chinese Thai Korean