Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 49 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
49
Dung lượng
855,07 KB
Nội dung
</managed-property> <managed-property> <description> Initializes the coords property of the managed bean, NA with the value specified by the value element. </description> <property-name>coords</property-name> <value> 53,109,1,110,2,167,19,168,52,149,67,164,67,165,68,167,70,168,72, 170,74,172,75,174,77,175,79,177,81,179,80,179,77,179,81,179,81, 178,80,178,82,211,28,238,15,233,15,242,31,252,36,247,36,246,32, 239,89,209,92,216,93,216,100,216,103,218,113,217,116,224,124, 221,128,230,163,234,185,189,178,177,162,188,143,173,79,173,73, 163,79,157,64,142,54,139,53,109 </value> </managed-property> </managed-bean> <! Business Logic Beans > <managed-bean> <description> Causes the default VariableResolver implementation to instantiate the managed bean, CustomerBean of the class, carstore.CustomerBean in session scope if the bean does not already exist in any scope. </description> <managed-bean-name> customer </managed-bean-name> <managed-bean-class> carstore.CustomerBean </managed-bean-class> <managed-bean-scope> session </managed-bean-scope> </managed-bean> <managed-bean> <description> The main backing file mean </description> <managed-bean-name> carstore </managed-bean-name> <managed-bean-class> carstore.CarStore </managed-bean-class> <managed-bean-scope> session </managed-bean-scope> </managed-bean> <navigation-rule> <from-view-id>/chooseLocale.jsp</from-view-id> <navigation-case> <description> Any action on chooseLocale should cause navigation to storeFront.jsp Listing 4.2 (continued) JSF Configuration 121 09_462071 Ch04.qxd 5/17/04 10:15 AM Page 121 </description> <to-view-id>/storeFront.jsp</to-view-id> </navigation-case> </navigation-rule> <navigation-rule> <from-view-id>/storeFront.jsp</from-view-id> <navigation-case> <description> Any action that returns “carDetail” on storeFront.jsp should cause navigation to carDetail.jsp </description> <from-outcome>carDetail</from-outcome> <to-view-id>/carDetail.jsp</to-view-id> </navigation-case> </navigation-rule> <navigation-rule> <from-view-id>/carDetail.jsp</from-view-id> <navigation-case> <description> Any action that returns “confirmChoices” on carDetail.jsp should cause navigation to confirmChoices.jsp </description> <from-outcome>confirmChoices</from-outcome> <to-view-id>/confirmChoices.jsp</to-view-id> </navigation-case> </navigation-rule> <navigation-rule> <from-view-id>/confirmChoices.jsp</from-view-id> <navigation-case> <description> Any action that returns “carDetail” on confirmChoices.jsp should cause navigation to carDetail.jsp </description> <from-outcome>carDetail</from-outcome> <to-view-id>/carDetail.jsp</to-view-id> </navigation-case> </navigation-rule> <navigation-rule> <from-view-id>/confirmChoices.jsp</from-view-id> <navigation-case> <description> Any action that returns “customerInfo” on confirmChoices.jsp should cause navigation to customerInfo.jsp Listing 4.2 (continued) 122 Chapter 4 09_462071 Ch04.qxd 5/17/04 10:15 AM Page 122 </description> <from-outcome>customerInfo</from-outcome> <to-view-id>/customerInfo.jsp</to-view-id> </navigation-case> </navigation-rule> <navigation-rule> <from-view-id>/customerInfo.jsp</from-view-id> <navigation-case> <description> Any action that returns “finish” on customerInfo.jsp should cause navigation to finish.jsp </description> <from-outcome>finish</from-outcome> <to-view-id>/finish.jsp</to-view-id> </navigation-case> </navigation-rule> </faces-config> Listing 4.2 (continued) The first thing you’ll notice, as with the web.xml file, is a document type declaration at the top of the file. The JSF specification defines the structure of a JSF configuration file via a publicly available DTD: http://java.sun.com/dtd/web-facesconfig_1_0.dtd Each JSF configuration file must adhere closely to this DTD or the associated application will likely fail to start. As part of the Car Demo sample, a JAR file named demo-components .jar is packaged in the /WEB-INF/lib/ directory of the WAR. This JAR is actually the result of another sample application called Demo Components that demonstrates the use of custom GUI components and Renderers. The associated faces-config.xml file is provided in Listing 4.3. We’ll refer to this file later when we discuss declaring UI components and Renderers. <!DOCTYPE faces-config PUBLIC “-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN” “http://java.sun.com/dtd/web-facesconfig_1_0.dtd”> <faces-config> <! Custom Components > Listing 4.3 JSF Configuration for custom UI components and Renderers. (continued) JSF Configuration 123 09_462071 Ch04.qxd 5/17/04 10:15 AM Page 123 <component> <component-type>DemoArea</component-type> <component-class> components.components.AreaComponent </component-class> <property> <description> Alternate text if we synthesize an ImageArea bean. </description> <property-name>alt</property-name> <property-class>java.lang.String</property-class> </property> <property> <description> Hotspot coordinates if we synthesize an ImageArea bean. </description> <property-name>coords</property-name> <property-class>java.lang.String</property-class> </property> <property> <description> Shape (default, rect, circle, poly) if we synthesize an ImageArea bean. </description> <property-name>shape</property-name> <property-class>java.lang.String</property-class> </property> </component> <component> <component-type>Graph</component-type> <component-class> components.components.GraphComponent </component-class> </component> <component> <component-type>DemoMap</component-type> <component-class> components.components.MapComponent </component-class> <property> <description> Alternate text for the currently selected child AreaComponent. </description> <property-name>current</property-name> <property-class>java.lang.String</property-class> </property> Listing 4.3 (continued) 124 Chapter 4 09_462071 Ch04.qxd 5/17/04 10:15 AM Page 124 </component> <component> <component-type>Pane</component-type> <component-class> components.components.PaneComponent </component-class> </component> <component> <component-type>Scroller</component-type> <component-class> components.components.ScrollerComponent </component-class> </component> <! Custom Renderers > <render-kit> <renderer> <description> Renderer for a components.components.AreaComponent component. </description> <renderer-type>DemoArea</renderer-type> <renderer-class>components.renderkit.AreaRenderer</renderer-class> <attribute> <description> Context-relative path to an image to be displayed when the mouse is not hovering over this hotspot. </description> <attribute-name>onmouseout</attribute-name> <attribute-class>java.lang.String</attribute-class> </attribute> <attribute> <description> Context-relative path to an image to be displayed when the mouse is hovering over this hotspot. </description> <attribute-name>onmouseover</attribute-name> <attribute-class>java.lang.String</attribute-class> </attribute> <attribute> <description> CSS style class to use when rendering this component. </description> <attribute-name>styleClass</attribute-name> <attribute-class>java.lang.String</attribute-class> </attribute> <supported-component-class> Listing 4.3 (continued) JSF Configuration 125 09_462071 Ch04.qxd 5/17/04 10:15 AM Page 125 <component-class> components.components.AreaComponent </component-class> </supported-component-class> </renderer> <renderer> <description> Renderer for a components.components.MapComponent component. </description> <renderer-type>DemoMap</renderer-type> <renderer-class>components.renderkit.MapRenderer</renderer-class> <attribute> <description> CSS style class to use when rendering this component. </description> <attribute-name>styleClass</attribute-name> <attribute-class>java.lang.String</attribute-class> </attribute> <supported-component-class> <component-class> components.components.MapComponent </component-class> </supported-component-class> </renderer> <renderer> <renderer-type>MenuBar</renderer-type> <renderer-class> components.renderkit.MenuBarRenderer </renderer-class> </renderer> <renderer> <renderer-type>MenuTree</renderer-type> <renderer-class> components.renderkit.MenuTreeRenderer </renderer-class> </renderer> <renderer> <description> Renderer for a UIData component that can serve as the basis for different markup creation for the components that are children of the child UIColumn components. </description> Listing 4.3 (continued) 126 Chapter 4 09_462071 Ch04.qxd 5/17/04 10:15 AM Page 126 <renderer-type>Repeater</renderer-type> <renderer-class> components.renderkit.RepeaterRenderer </renderer-class> </renderer> <renderer> <renderer-type>Stylesheet</renderer-type> <renderer-class> components.renderkit.StylesheetRenderer </renderer-class> </renderer> <renderer> <renderer-type>TabLabel</renderer-type> <renderer-class> components.renderkit.TabLabelRenderer </renderer-class> </renderer> <renderer> <renderer-type>Tab</renderer-type> <renderer-class> components.renderkit.TabRenderer </renderer-class> </renderer> <renderer> <renderer-type>Tabbed</renderer-type> <renderer-class> components.renderkit.TabbedRenderer </renderer-class> </renderer> </render-kit> </faces-config> Listing 4.3 (continued) The <faces-config> Element This element is the root of every faces configuration file and contains all con- figuration settings for a JSF application other than those defined in the Web application descriptor. A summary of each possible child element is provided in Table 4.2. JSF Configuration 127 09_462071 Ch04.qxd 5/17/04 10:15 AM Page 127 Table 4.2 <faces-config> Child Elements CHILD ELEMENT MULTIPLICITY DESCRIPTION application zero to many You may optionally replace the default action listener, navigation handler, property resolver, and variable resolver for your application. factory zero to many Provides factory implementations of things like faces context, life cycle, render kit, and application resources. component zero to many Custom UI components (other than standard JSF components). converter zero to many Converters for encoding and decoding UI component values. managed-bean zero to many Objects that are automatically created, initialized, and placed into proper scope when invoked by a UI component. navigation-rule zero to many Navigation rules that are used in the decision flow of your application. referenced-bean zero to many Bean references that are expected to be in scope where used in your user interface code. render-kit zero to many RenderKits for rendering UI components in your application. lifecycle zero to many Provides modifications to the default life cycle. validator zero to many Validators for ensuring the correctness of data entered by users in application UI components. We’ll cover each of these elements, along with their child elements, in the following sections. The <application> Element This element allows you to replace the default action handler, navigation handler, and resolvers for properties and variables. Replacing the defaults pro- vided with your JSF implementation is unnecessary for most applications but may be done if one or more of them are inadequate. A summary of each possi- ble child element is provided in Table 4.3. 128 Chapter 4 09_462071 Ch04.qxd 5/17/04 10:15 AM Page 128 Table 4.3 <application> Child Elements CHILD ELEMENT MULTIPLICITY DESCRIPTION action-listener zero to many The fully qualified class name of the concrete ActionListener implementation class that processes action events emitted from UI components. message-bundle zero to many Base name (and optionally package when appropriate) of a resource bundle that contains message resources for the application (see the JavaDocs for java.util.ResourceBundle for more information). navigation-handler zero to many The fully qualified class name of the concrete NavigationHandler implementation class that determines next steps in application flow. view-handler zero to many The fully qualified class name of the concrete ViewHandler implementation class that is called by the Restore View and Render Response phases of the request processing life cycle. property-resolver zero to many The fully qualified class name of the concrete PropertyResolver implementation class that resolves all property references in your application. variable-resolver zero to many The fully qualified class name of the concrete VariableResolver implementation class that resolves all variable references in your application. local-config zero to many Provides supported locales supported by the application (including an optional default). The Car Demo application, like typical JSF applications, does not replace these default resources provided by the JSF implementation. The <factory> Element This element allows you to declaratively provide factory implementations of things like the faces context, life cycle, render kits, and application resources. A summary of each possible child element is provided in Table 4.4. JSF Configuration 129 09_462071 Ch04.qxd 5/17/04 10:15 AM Page 129 Table 4.4 <factory> Child Elements CHILD ELEMENT MULTIPLICITY DESCRIPTION application-factory zero to many The fully qualified class name of the ApplicationFactory implementation class (its instances provide a host of basic resources and behavior needed by JSF applications) that should replace the default provided by your JSF implementation. faces-context-factory zero to many The fully qualified class name of the FacesContextFactory implementation class (which provides FacesContext instances) that should replace the default provided by your JSF implementation. lifecycle-factory zero to many The fully qualified class name of the LifecycleFactory implementation class (the Lifecycle instances it provides manage the entire JSF request- processing life cycle) that should replace the default provided by your JSF implementation. render-kit-factory zero to many The fully qualified class name of the RenderKitFactory implementation class (provides access to available render kits) that should replace the default provided by your JSF implementation. This element allows you to add custom extensions to your JSF implementa- tion. Most JSF developers won’t use this mechanism, but it is very useful when adjustments to a particular JSF implementation are necessary. The <message-bundle> and <local-config> Elements The <message-bundle> element represents a bundle of localized messages, while the <local-config> element defines all supported locales (including an optional default). You can use these elements to support internationaliza- tion in your application. Listing 4.2 provides a good example of these elements in action. <application> <message-bundle>carstore.bundles.Messages</message-bundle> <locale-config> <default-locale>en</default-locale> 130 Chapter 4 09_462071 Ch04.qxd 5/17/04 10:15 AM Page 130 [...]... coords 53,109,1,110,2,167,19,168,52, 149 ,67,1 64, 67,165,68,167,70,168, 72,170, 74, 172,75,1 74, 77,175,79,177,81,179,80,179,77,179,81,179, 81,178,80,178,82,211,28,238,15,233,15, 242 ,31,252,36, 247 ,36, 246 , 32,239,89,209,92,216,93,216,100,216,103,218,113,217,116,2 24, 1 24, 221,128,230,163,2 34, 185,189,178,177,162,188, 143 ,173,79,173, 73,163,79,157, 64, 142 , 54, 139,53,109 ... point in the flow of your application’s user interface The navigation rule elements you define will be used by the default NavigationHandler of your JSF implementation (or the one you optionally replace it with using the application element) to determine next steps in your workflow A summary of each possible child element is provided in Table 4. 14 Table 4. 14 Child Elements CHILD ELEMENT... component trees navigation-case zero to many Defines one possible outcome for the navigation rule 143 144 Chapter 4 The element is used to define either an outcome that applies to all pages in the application or one that applies specifically when coming from a particular page The code in Listing 4. 2 provides the application flow for Car Demo, a piece of which is repeated here ... one possible outcome for a navigation rule and specifies what component tree should be displayed next, based on that outcome A summary of each possible child element is provided in Table 4. 15 145 146 Chapter 4 Table 4. 15 Child Elements CHILD ELEMENT MULTIPLICITY DESCRIPTION description zero to many A textual description of the navigation case display-name zero to many A short, descriptive... will default to a type of String We specified the class for all values so that they will automatically be converted to a type of java.math.BigDecimal You must be sure that your values (and 141 142 Chapter 4 Table 4. 12 Child Elements CHILD ELEMENT MULTIPLICITY DESCRIPTION key exactly one Provides the String representation of the key null-value or value exactly one Provides the value associated... provided in Table 4. 9 Table 4. 9 Child Elements CHILD ELEMENT MULTIPLICITY DESCRIPTION description zero to many A textual description of the managed bean display-name zero to many A short, descriptive name of the managed bean for display in JSF tools icon zero to many Small and large icons for representing the managed bean in JSF tools (continued) 137 138 Chapter 4 Table 4. 9 (continued)... the referenced bean is expected to be located in one of the scopes referenced-beanclass exactly one Represents the fully qualified class name of the Java class or interface implemented by the corresponding referenced bean 147 148 Chapter 4 A JDBC data source that supplies our Customer information will be initialized and made available in some scope for the Car Demo application... address: http://www.jamesholmes.com/JavaServerFaces/console/ The Faces Console fully supports the creation and modification of JSF configuration files and plugs into many widely used Java IDEs Those of you familiar with the popular Struts Console tool will feel right at home with this one The Car Demo configuration file is shown with Faces Console in Figure 4. 5 There will likely be more visual, drag-and-drop-style... Defines a generic JavaBean property on the UI component componentextension zero or more Provides a place for content specific to a particular JSF implementation 133 1 34 Chapter 4 There are a number of custom UI components defined in Listing 4. 3, one of which is repeated here DemoArea components.components.AreaComponent ... class attribute zero to many Defines a generic attribute for the Renderer supportedcomponent-type zero to many Registers support for rendering a UI component by its type identifier (continued) 149 150 Chapter 4 Table 4. 18 (continued) CHILD ELEMENT MULTIPLICITY DESCRIPTION supportedcomponent-class zero to many Registers support for rendering a UI component by its implementation class name renderer-extension . element. </description> <property-name>coords</property-name> <value> 53,109,1,110,2,167,19,168,52, 149 ,67,1 64, 67,165,68,167,70,168,72, 170, 74, 172,75,1 74, 77,175,79,177,81,179,80,179,77,179,81,179,81, 178,80,178,82,211,28,238,15,233,15, 242 ,31,252,36, 247 ,36, 246 ,32, 239,89,209,92,216,93,216,100,216,103,218,113,217,116,2 24, 1 24, 221,128,230,163,2 34, 185,189,178,177,162,188, 143 ,173,79,173,73, 163,79,157, 64, 142 , 54, 139,53,109 </value> </managed-property> </managed-bean> . element. </description> <property-name>coords</property-name> <value> 53,109,1,110,2,167,19,168,52, 149 ,67,1 64, 67,165,68,167,70,168,72, 170, 74, 172,75,1 74, 77,175,79,177,81,179,80,179,77,179,81,179,81, 178,80,178,82,211,28,238,15,233,15, 242 ,31,252,36, 247 ,36, 246 ,32, 239,89,209,92,216,93,216,100,216,103,218,113,217,116,2 24, 1 24, 221,128,230,163,2 34, 185,189,178,177,162,188, 143 ,173,79,173,73, 163,79,157, 64, 142 , 54, 139,53,109 </value> </managed-property> </managed-bean> . AreaComponent. </description> <property-name>current</property-name> <property-class>java.lang.String</property-class> </property> Listing 4. 3 (continued) 1 24 Chapter 4 09 _46 2071 Ch 04. qxd 5/17/ 04 10:15 AM Page 1 24 </component> <component> <component-type>Pane</component-type> <component-class> components.components.PaneComponent </component-class> </component> <component> <component-type>Scroller</component-type> <component-class> components.components.ScrollerComponent </component-class> </component> <!