How to Create a Class for a Component

30-30 Web User Interface Developers Guide for Oracle Application Development Framework Example 30–17 Registering a Resource Bundle with a Skin skins xmlns=http:myfaces.apache.orgtrinidadskin skin-addition skin-idsimple.desktopskin-id style-sheet-namestyle-sheet-name bundle-name oracle.adfdemo.acme.faces.resource.AcmeSimpleDesktopBundle bundle-name skin-addition skins

30.4.7 How to Create a Class for a Renderer

ADF Faces components delegate the functionality of the component to a component class, and when the consuming application uses JSPs, the display of the component to a renderer. By default, all tags for ADF Faces combine the associated component class with an HTML renderer, and are part of the HTML render kit. HTML render kits are included with ADF Faces for display on both desktop and PDA devices. Renderers are qualified in a render kit by family and renderer type. The family is a general categorization for a component, and should be the same as the family defined in the superclass. You do not have to override the getFamily method in the component because the component will have the method through inheritance. To create the renderer class: 1. In the Application Navigator, right-click the project and select New. 2. In the New Gallery, expand General then select Java. 3. Select Java Class and click OK. 4. In the Create Java Class File dialog, do the following: ■ Name : Enter a renderer name. For example, for the tagPane component, you might enter TagPaneRenderer. ■ Package : Enter a name for the package. For example, for the tagPane component, you might enter oracle.adfdemo.acme.faces.render. ■ Extends : Enter oracle.adf.view.rich.render.RichRenderer. ■ In the Optional Attributes section, select the following:. – In the Access Modifiers section, select public. – At the bottom, select Constructors from Superclass and Implement Abstract Methods . 5. Add any needed functionality. For example, the skinning functionality provides an API you can use to get the CSS style properties for a given CSS selector during rendering of the component. This API is useful if you need to do conditional rendering based on what styling is set. For more information, see RenderingContextgetStyles and StylesgetSelectorStyleMap in the MyFaces Trinidad Javadoc at http:myfaces.apache.orgtrinidadtrinidad-1_ 2trinidad-apiapidocsindex.html . Creating Custom ADF Faces Components 30-31

30.4.8 How to Add the Renderer to the faces-config.xml File

After you create the renderer, register it using the faces-config.xml configuration file. If you want the custom component to work with the other ADF Faces components, you must use the same render kit ID that ADF Faces components use. To register the render kit and renderer: 1. In the Application Navigator, double-click the faces-config.xml file to open it in the editor.

2. Select the Overview tab and then select the Render Kits navigation tab.

3. Click the Add icon for the Render Kits and enter oracle.adf.rich for the

render kit ID.

4. Register your renderer by clicking the Add icon for Renderers and doing the

following: ■ Family : Enter the class that the component extends. For example, for the tagPane component, you would enter org.apache.myfaces.trinidad.Object. ■ Type : Enter the type for the component. For example, for the tagPane component, you would enter oracle.adfdemo.acme.TagPane. This must match the renderer type. ■ Class : Enter the fully qualified class path to the renderer created in Section 30.4.7, How to Create a Class for a Renderer. For example, for the tagPane component, you would enter oracle.adfdemo.acme.faces.render.TagPaneRenderer. Example 30–18 shows the registration of the tagPane component render kit and renderer. Example 30–18 tagPane Renderer Added to the faces-config.xml File render-kit render-kit-idoracle.adf.richrender-kit-id renderer component-familyorg.apache.myfaces.trinidad.Objectcomponent-family renderer-typeoracle.adfdemo.acme.TagPanerenderer-type renderer-classoracle.adfdemo.acme.faces.render.TagPaneRenderer renderer-class renderer render-kit

30.4.9 How to Create JSP Tag Properties

To use the component on a JSP page, you create a custom tag that will instantiate the custom component. The JSP tag has nothing to do with rendering because the component’s renderer will actually perform that task. In JSF 1.1, the JSP tag would invoke rendering on the component after creating and adding it to the component tree. This caused problems because the non-JSFJSP tags were writing to the same response writer. The timing of the interleaving did not work out for components that rendered their own child components. Tip: The most granular level that JSF allows for defining a render kit is at the view root. 30-32 Web User Interface Developers Guide for Oracle Application Development Framework In JSF 1.2, the target for Java EE 5 Servlet 2.5, JSP 2.1, most of the JSP problems were fixed. The JSFJSP component acts as a component factory that is responsible only for creating components. This means that the rendering response phase is divided into two steps. First the component tree is created, and then the tree is rendered, instead of rendering the components as the component tree was being built. This functionality was made possible by insisting that the entire view be represented by JSF components. The non-JSFJSP generates markup that implicitly becomes a JSF verbatim component. As a result of changing these mechanics, in JSF 1.2, custom JSP tags extend the javax.faces.webapp.UIComponentELTag class. The encodeBegin, encodeChildren, and encodeEnd methods in the JSP tag have been deprecated. These methods once made corresponding calls to the component. Because the view root in JSF 1.2 does the rendering, all the work can be done in the doStartTag and doEndTag methods. MyFaces Trinidad has its own version of this base class that you will use. The org.apache.myfaces.Trinidad.webapp.UIComponentELTag hooks into the components property bag and makes coding JSPs simpler. The tag class includes the creation of the component’s properties. You must choose tag properties carefully. There are some properties that you can ignore for tag implementation, but they may be required as TLD attributes. The following three attributes are implemented by superclasses and shared by many components through Java inheritance: ■ id ■ binding ■ rendered Do not implement the id attribute because the id attribute is implemented by the superclass javax.faces.webapp.UIComponentTagBase. The superclass javax.faces.webapp.UIComponentELTag implements the other two attributes, binding and rendered. Therefore, you do not need to add these to your tag class. To add a JSP tag: 1. In the Application Navigator, right-click the project and select New. 2. In the New Gallery, expand General then select Java. 3. Select Java Class and click OK. 4. In the Create Java Class File dialog, do the following: ■ Name : Enter a tag name. For example, for the tagPane component, you might enter TagPaneTag. ■ Package : Enter a name for the package. For example, for the tagPane component, you might enter oracle.adfdemo.acme.faces.taglib. ■ Class : Enter org.apache.myfaces.trinidad.webapp.UIXComponentELTag. ■ In the Optional Attributes section, select the following:. – In the Access Modifiers section, select public. Note: An application that uses Facelets uses a handler to instantiate the component. For more information, see Section 30.2.8, How to Add a Facelets Tag Library Configuration File