Chapter: Internet & World Wide Web HOW TO PROGRAM - Rich Internet Application Server Technologies - JavaServer™ Faces Web Applications

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail

Examining a JSP File

The JSP files used in this and the following examples are generated almost entirely by Net-beans, which provides a Visual Editor that allows you to build a page’s GUI by dragging and dropping components onto a design area.

Examining a JSP File

 

The JSP files used in this and the following examples are generated almost entirely by Net-beans, which provides a Visual Editor that allows you to build a page’s GUI by dragging and dropping components onto a design area. The IDE generates a JSP file in response to your interactions. Line 1 of Fig. 26.1 is the XML declaration, indicating the fact that the JSP is expressed in XML syntax and the version of XML that is used. Lines 3–5 are com-ments that we added to the JSP to indicate its figure number, filename and purpose.

 

Line 6 begins the JSP’s root element. All JSPs must have this jsp:root element, which has a version attribute to indicate the JSP version being used (line 6) and one or more xmlns attributes (lines 7–10). Each xmlns attribute specifies a prefix and a URL for a tag library, allowing the page to use tags from that library. For example, line 9 allows the page to use the standard JSP elements. To use these elements, each element’s tag must be preceded by the jsp prefix. All JSPs generated by Netbeans include the tag libraries spec-ified in lines 7–10 (the JSF core components library, the JSF HTML components library, the JSP standard components library and the JSF user interface components library).

 

Lines 11–12 are the jsp:directive.page element. Its contentType attribute specifies the MIME type (text/html) and the character set (UTF-8) the page uses. The page- Encoding attribute specifies the character encoding used by the page source. These attributes help the client (typically a web browser) determine how to render the content.

All pages containing JSF components are represented in a component tree (Fig. 26.2) with the root JSF element f:view, which is of type UIViewRoot. This component tree structure is represented in a JSP by enclosing all JSF component tags inside the f:view element (lines 13–37).

 

Lines 14–21 begin the JSP’s definition with the webuijsf:page, webuijsf:html and webuijsf::head tags, all from the webuijsf (JSF user interface components) tag library. These and many other webuijsf page elements have a binding attribute. For example, the webuijsf:head element (line 16) has the attribute binding = "#{Time.head1}." This attribute uses JSF Expression Language notation (i.e., #{Time.head1}) to reference the head1 property in the Time class that represents the page bean (you’ll see this class in Fig. 26.3). You can bind an attribute of a JSP element to a property in any of the web appli-cation’s JavaBeans. For instance, the text attribute of a webuijsf:label component can be bound to a String property in the application’s SessionBean (shown in Section 26.5.2).

 

The webuijsf:head element (lines 16–21) has a title attribute that specifies the page’s title. This element also contains a webuijsf:link element (lines 18–19) that spec-ifies the CSS stylesheet used by the page, and a webuijsf:meta element (line 20) that spec-ifies the page’s refresh rate. The webuijsf:body element (lines 22–34) contains a webuijsf:form element (lines 24–33), which contains two webuijsf:staticText components (lines 25–28 and 29–32) that display the page’s text. The timeHeader component (lines 25–28) has a text attribute (line 28) that specifies the text to display (i.e., "Current time on the web server"). The clockText component (lines 29–32) does not specify a text attribute because this component’s text will be set programmatically.


For the markup in this file to be displayed in a browser, all the JSP’s elements are auto-matically mapped to XHTML elements that the browser recognizes. The same web com-ponent can map to different XHTML elements, depending on the client browser and the component’s property settings. In this example, the webuijsf:staticText components (lines 25–28, 29–32) map to XHTML span elements. A span element contains text that is displayed on a web page and is typically used to control the formatting of the text. The style attributes of a JSP’s webuijsf:staticText element will be represented as part of the corresponding span element’s style attribute when the browser renders the page. We show momentarily the XHTML document that results when Time.jsp is requested by a browser.

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail


Copyright © 2018-2020 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.