Creating a custom component

A custom component library contains new and modified JSF components that you can use in your Web applications and distribute the libraries to your development team.

Create a custom component library.

To create and add a custom component to a custom component library.

  1. Click

    File | New | Other | Web | Faces Custom Component. Click Next. The New Web Page wizard opens.

  2. In the

    File Name field, type a file name for your custom component. In the Template list, click

    Faces Custom Component. Then click Finish. The JSP opens.

    This JSP is a JSF page fragment that wraps custom component tags within the <jsfc:component> tags:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
    
    <%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <%@taglib uri="http://www.ibm.com/jsf/customcomponent" prefix="jsfc"%>
    
    <jsfc:component>
    </jsfc:component>

    The custom component tag, <jsfc:component>, contains the other JSF components that you will add to your custom component.

  3. Define the attributes for the custom component tag.

  4. Add your custom component tags to the JSP. You can add the tags using different methods:

    • Type the tags into the Source view of Page Designer.

    • Drop an existing tag or group of tags from the Palette onto the page.

    • Drop the component from the Page Data View onto the page.
    Save the file. The JSF component, tag class, and associated configuration files are created in the component library project. The new JSF component class, custom tag class for each custom component page, faces-config.xml, and tag library definition (TLD) file is added to the tag library JAR file.

    Tip: A test page is automatically generated when you save the component. To test your component, right-click the test page in Enterprise Explorer and select

    Run As | Run on Server. Follow the instructions in the Run On Server wizard.

Once you have added your custom component to your custom library, you can use your custom components to create page content. To add the custom components to the palette, refer to Adding support for an existing component library. To distribute the components to other users, refer to Distributing a JSF component library.