How to Create a Class for an Event

Creating Custom ADF Faces Components 30-27 { return TYPE; } Refer to the ADF Faces JavaDoc for more information about the class your component extends, and the methods you may need to override. For the tagPane component, the component must act on the event fired from the client component. A reference to the source component is passed as a parameter to the event’s constructor. For the tagPane component, the broadcast method checks if the event passed in using the formal parameter is a TagSelectEvent. If it is, the broadcast method invokes the method expression held by the tagSelectListener attribute. Most events have an immediate boolean property that specifies the lifecycle phase in which the event should be invoked. If the immediate attribute is true, the event is processed in the Apply Values phase; otherwise, the event is processed in the Invoke Application phase. For more information, see Chapter 4, Using the JSF Lifecycle with ADF Faces. Example 30–14 shows the overwritten broadcast method for the tagPane component. Example 30–14 The broadcast Method in the tagPane Component param facesEvent faces event throws AbortProcessingException exception during processing Override public void broadcastFacesEvent facesEvent throws AbortProcessingException { notify the bound TagSelectListener if facesEvent instanceof TagSelectEvent { TagSelectEvent event = TagSelectEvent facesEvent; utility method found in UIXComponentBase for invoking method event expressions broadcastToMethodExpressionevent, getTagSelectListener; } super.broadcastfacesEvent; }

30.4.5 How to Add the Component to the faces-config.xml File

After creating the component class, register the component by adding it to the META-INFfaces-config.xml file. By defining the component in the faces configuration file packaged with the JAR project, you ensure that component is automatically recognized by the JSF runtime during web application startup. To register the component, enter the component type, which is a logical name used by the applications factory to instantiate an instance of the component. For example, the tagPane component’s type is oracle.adfdemo.acme.TagPane. You also need to add the fully qualified class path for the component, for example oracle.adfdemo.acme.faces.component.TagPane. 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.