Standard JSF Tags Mimi Opkins CECS 493 Fall 2016.

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

24-Aug-14 HTML Forms. 2 What are forms? is just another kind of HTML tag HTML forms are used to create (rather primitive) GUIs on Web pages Usually the.
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
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.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 3-1 of…
Creating Web Page Forms
ASP.NET Programming with C# and SQL Server First Edition
® IBM Software Group © 2006 IBM Corporation JSF Tab Controls This Learning Module shows how to develop server-side EGL applications with dynamic content.
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
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
Chapter 4 Dreamweaver: Part II The Web Warrior Guide to Web Design Technologies.
_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
Event-driven Programming
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 4-1 of…
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
10 Adding Interactivity to a Web Site Section 10.1 Define scripting Summarize interactivity design guidelines Identify scripting languages Compare common.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
JavaScript: Functions © by Pearson Education, Inc. All Rights Reserved.
© 2010 Delmar, Cengage Learning Chapter 8 Collecting Data with Forms.
Using Client-Side Scripts to Enhance Web Applications 1.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
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.
CSCI 6962: Server-side Design and Programming JSF DataTables and Shopping Carts.
CSCI 6962: Server-side Design and Programming Facelets and User Interface Design.
©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.
Chapter 12© copyright Janson Industries Java Server Faces ▮ Explain the JSF framework ▮ SDO (service data objects) ▮ Facelets ▮ Pagecode classes.
Learning Aim C.  In this section we will look at how text, tables, forms and frames can be used in web pages.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
HTML Tutorial. What is HTML HTML is a markup language for describing web documents (web pages) HTML documents are described by HTML tags Each HTML tag.
Simple PHP Web Applications Server Environment
Navigation Mimi Opkins CECS 493 Fall Static Navigation  In a simple web application, navigation is static. That is, clicking a particular button.
Facelets Mimi Opkins CECS493 Fall Facelets  User interfaces are typically a web application’s most volatile aspect during development, and they.
Intro to JavaServer Faces Mimi Opkins CECS 493 Fall 2016.
JSF Conversion and Validation
Section 10.1 Define scripting
DHTML.
JavaScript, Sixth Edition
In this session, you will learn to:
Event Handling Mimi Opkins CECS 493 Fall 2016.
Chapter 6 JavaScript: Introduction to Scripting
How to Write Web Forms By Mimi Opkins.
Play Framework: Introduction
ASP.NET Web Controls.
Tutorial 6 Topic: jQuery and jQuery Mobile Li Xu
Arrays and files BIS1523 – Lecture 15.
Intro to PHP & Variables
HTML Forms and User Input
Web Programming A different world! Three main languages/tools No Java
Chapter 27 WWW and HTTP.
Forms, cont’d.
Working with Text and Cascading Style Sheets
Using Cascading Style Sheets (CSS)
Building ASP.NET Applications
Creating Forms on a Web Page
SEEM4570 Tutorial 5: jQuery + jQuery Mobile
Web Development Using ASP .NET
Using Templates and Library Items
Creating Additional Input Items
Unit J: Creating a Database
Web Programming and Design
Presentation transcript:

Standard JSF Tags Mimi Opkins CECS 493 Fall 2016

JSF Tag Libraries  As of JSF 2.0, there are six libraries with over 100 tags

JSF Core Tags  The core library contains the tags that are independent of HTML rendering

JSF Core Tags  The core library contains the tags that are independent of HTML rendering  Most of the core tags represent objects you add to components, such as the following:  Attributes  Parameters  Facets  Listeners  Converters  Validators  Selection items

Attributes, Parameters, and Facets  The f:attribute, f:param, and f:facet tags are general-purpose tags to add information to a component. Any component can store arbitrary name/value pairs in its attribute map. You can set an attribute in a page and later retrieve it programmatically.  The converter that formats the output retrieves the attribute from the component.  The f:param tag also lets you define a name/value pair, but the value is placed in a separate child component, a much bulkier storage mechanism. However, the child components form a list, not a map. You use f:param if you need to supply a number of values with the same name (or no name at all).  The h:commandlink component turns its f:param children into HTTP request name/value pairs. The event listener that is activated when the user clicks the link can then retrieve the name/value pairs from the request map.  Finally, f:facet adds a named component to a component’s facet map. A facet is not a child component; each component has both a list of child components and a map of named facet components. The facet components are usually rendered in a special place. The root of a Facelets page has two facets named "head" and "body".

Attributes for f:attribute, f:param, and f:facet

An Overview of the JSF HTML Tags  We can group these tags in the following categories:  Inputs (input...)  Outputs (output..., graphicImage)  Commands (commandButton and commandLink)  GET Requests (button, link, outputLink)  Selections (checkbox, listbox, menu, radio)  HTML pages (head, body, form, outputStylesheet, outputScript)  Layouts (panelGrid, panelGroup)  Data table (dataTable and column); see Chapter 6  Errors and messages (message, messages)

JSF HTML Tags

Common Attributes  The JSF HTML tags share common attributes, HTML pass-through attributes, and attributes that support dynamic HTML.  Three types of tag attributes are shared among multiple HTML component tags:  Basic  HTML 4.0  DHTML events

 All components can have id, binding, and rendered attributes  The value and converter attributes let you specify a component value and a means to convert it from a string to an object, or vice versa.  The validator, required, and valueChangeListener attributes are available for input components so that you can validate values and react to changes to those values.

IDs  The versatile id attribute lets you do the following:  Access JSF components from other JSF tags  Obtain component references in Java code  Access HTML elements with scripts  The id attribute lets page authors reference a component from another tag. For example, an error message for a component can be displayed like this:

Values, Converters, and Validators  Inputs, outputs, commands, and data tables all have values. Associated tags in the HTML library, such as h:inputText and h:dataTable, come with a value attribute. You can specify values with a string, like this:  Most of the time you will use a value expression—for example:  The converter attribute, shared by inputs and outputs, lets you attach a converter to a component. Input tags also have a validator attribute that you can use to attach a validator to a component.

Conditional Rendering  You use the rendered attribute to include or exclude a component, depending on a condition. For example, you may want to render a “Logout” button only if the user is currently logged in:  To conditionally include a group of components, include them in an h:panelGrid with a rendered attribute.

Resources  You can include a stylesheet in the usual way, with an HTML link tag.  But that is tedious if your pages are at varying directory nesting levels—you would always need to update the stylesheet directory when you move a page. More importantly, if you assemble pages from different pieces,  Since JSF 2.0, there is a better way.  You can place stylesheets, JavaScript files, images, and other files into a resources directory in the root of your web application.  Subdirectories of this directory are called libraries. You can create any libraries that you like. In this book, we often use libraries css, images, and javascript.

Including Stylesheets  To include a stylesheet, use the tag:  The tag adds a link of the form  to the header of the page.

Including Scripts  To include a script resource, use the outputScript tag instead:  If the target attribute is head or body, the script is appended to the "head" or "body" facet of the root component, which means that it appears at the end of the head or body in the generated HTML.  If there is no target element, the script is inserted in the current location.

Including Images  To include an image from a library, you use the graphicImage tag:

DHTML Events  Client-side scripting is useful for all sorts of tasks, such as syntax validation or rollover images, and it is easy to use with JSF.  HTML attributes that support scripting, such as onclick and onchange are called dynamic HTML (DHTML) event attributes.  JSF supports DHTML event attributes for nearly all of the JSF HTML tags

DHTML Event Attributes

Messages  During the JSF life cycle, any object can create a message and add it to a queue of messages maintained by the faces context.  At the end of the life cycle—in the Render Response phase—you can display those messages in a view.  Typically, messages are associated with a particular component and indicate either conversion or validation errors.  Although error messages are usually the most prevalent message type in a JSF application, messages come in four varieties:  Information  Warning  Error  Fatal

Message Tags  All messages can contain a summary and a detail. For example, a summary might be Invalid Entry and a detail might be The number entered was greater than the maximum.  JSF applications use two tags to display messages in JSF pages: h:messages and h:message.  The h:messages tag displays all messages that were stored in the faces context during the course of the JSF life cycle. You can restrict those messages to global messages—meaning messages not associated with a component—by setting h:message’s globalOnly attribute to true. By default, that attribute is false.  The h:message tag displays a single message for a particular component. That component is designated with h:message’s mandatory for attribute. If more than one message has been generated for a component, h:message shows only the last one.

Attributes for h:message and h:messages

 The majority of the attributes in the prior table represent CSS classes or styles that h:message and h:messages apply to particular types of messages.  You can also specify whether you want to display a message’s summary or detail, or both, with the showSummary and showDetail attributes, respectively.  The h:messages layout attribute can be used to specify how messages are laid out, either as a list or a table. I  f you specify true for the tooltip attribute and you have also set showDetail and showSummary to true, the message’s detail will be wrapped in a tooltip that is shown when the mouse hovers over the error message.

Displaying messages  Now that we have a grasp of message fundamentals, we take a look at an application that uses the h:message and h:messages tags. The application below contains a simple form with two text fields. Both text fields have required attributes.

 Moreover, the “Age” text field is wired to an integer property, so its value is converted automatically by the JSF framework. The previous figure shows the error messages generated by the JSF framework when we neglect to specify a value for the “Name” field and provide the wrong type of value for the “Age” field.  At the top of the JSF page, we use h:messages to display all messages. We use h:message to display messages for each input field:

Note that the input fields have label attributes that describe the fields. These labels are used in the error messages—for example, the Age: label (generated by #{msgs.agePrompt}) in this message: Age: 'old' must be a number between and Example: 9346 Both message tags in our example specify a CSS class named errors, which is defined in styles.css. That class definition looks like this:

Messages displayed as a list  We have also specified layout="table" for the h:messages tag. If we had omitted that attribute (or alternatively specified layout="list"), the output would look like that shown below.  The list layout encodes the error messages in an unnumbered list (whose appearance you can control through styles).  By default, h:messages shows message summaries but not details. h:message, on the other hand, shows details but not summaries. If you use h:messages and h:messag e together summaries will appear at the top of the page, with details next to the appropriate input field.

Directory structure for the messages example

messages/web/index.xhtml

messages/src/java/com/corejsf/messages.properties

messages/web/resources/css/styles.css

Additional HTML Tags  JSF has additional tags available for HTML 4.0 compatibility  Layout  Forms  Tables