Creating the Component Server-Side Development

30-28 Web User Interface Developers Guide for Oracle Application Development Framework To register a custom component: 1. In the Application Navigator, double-click the faces-config.xml file.

2. Click the Overview tab and click the Components navigation tab.

3. Click the Add icon and enter the type and class for the component.

4. Optionally, add any attributes, properties, or facets. Example 30–15 shows the tagPane component defined within a faces-config.xml file. Example 30–15 tagPane Component Added to the faces-config.xml File ?xml version=1.0 encoding=UTF-8 ? faces-config version=1.2 xmlns=http:java.sun.comxmlnsjavaee application application component component-typeoracle.adfdemo.acme.TagPanecomponent-type component-classoracle.adfdemo.acme.faces.component.TagPane component-class component

30.4.6 How to Create a Class for a Resource Bundle

Resource bundles are used to store information for the component, such as text for labels and messages, as well as translated text used if the application allows locale switching. Skins also use resource bundles to hold text for components. Because your custom component must use at least the simple skin, you must create at least a resource bundle for that skin. For a custom component, create a Java file for the resource bundle. For more information about resource bundle classes, see Section 20.3, Defining Skin Style Properties. To create the resource bundle class: 1. In the Application Navigator, right-click the project and select New. 2. In the New Gallery, expand General and select Java. 3. Select Java Class and click OK. 4. In the Create Java Class File dialog, do the following: ■ Name : Enter a resource bundle name. The name should reflect the skin with which it will be used. For example, for the sample component, you might enter AcmeSimpleDesktopBundle. ■ Package : Enter a name for the package. For example, for the sample component, you might enter oracle.adfdemo.acme.faces.resource. ■ Extends : For resource bundles, you must enter java.util.ListResourceBundle. ■ 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 . Tip: You can also use a properties file for your resources. Creating Custom ADF Faces Components 30-29 5. Add any keys and define the text as needed. For more information about creating resource bundles for skins, see Section 20.3.1, How to Apply Skins to Text. Example 30–16 shows the resource bundle code for the tagPane component. Example 30–16 tagPane Resource Bundle Java Code package oracle.adfdemo.acme.faces.resource; import java.util.ListResourceBundle; pHolds properties used by the components bundled in the jar project. This bundle is part of the trinidad component skin that is configured in the META-INFtrinidad-skins.xml file. Component Renderers will use the codeRenderingContextcode to lookup a key by calling the codegetTranslatedStringkeycode method.p public class AcmeSimpleDesktopBundle extends ListResourceBundle { pReturns a two dimensional object array that represents a resource bundle . The first element of each pair is the key and the second the value.p return an array of value pairs protected Object[][] getContents { return new Object[][] { {AcmeTagPane_tag_title,Tag Weight: {0}} }; } } 6. To register the resource bundle for the simple desktop skin and any other desired skins, double-click the META-INFtrinidad-skins.xml file to open it and do the following:

a. In the Structure window, select skin-addition.

b. In the Property Inspector, enter a skin ID. For the simple skin ID, enter simple.desktop.

c. In the Structure window, right-click skin-addition and choose Insert inside

skin-addition bundle-name. d. In the Property Inspector, enter the fully qualified name of the resource bundle just created. Example 30–17 shows the code for registering the tagPane resource bundle with the simple skin you will add the style-sheet-name element value in a later step. Note: JDeveloper adds translation-source and bundle-name elements as comments. Instead of declaratively creating another bundle-name element, you can manually enter the bundle-name value in the generated element, and then remove the comment tag. 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 .