Adding a JSF Form to a JSP Page

See Also

A UIForm component represents an input form that has child components representing data that is either presented to the user or submitted with the form. You can create an empty form or generate form code from an existing entity class. For more infomation about JSF form components, see need link here.

To generate an empty JSF form:

  1. Open any JSP page.
  2. Make sure that you have declared the JSF tag libaries in the page, as shown below:
    <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
    <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
  3. In the Palette window, expand the JSF category. Click and drag the JSF Form entry into the desired location in the JSP file and release the mouse button.
  4. In the dialog box, select Empty Table and click OK.

    The IDE enters the following code in the JSP page:

    <f:view>
       <h:form>
       </h:form>
    </f:view>

To generate a JSF form from an entity class:

  1. Open any JSP page.
  2. Make sure that you have declared the JSF tag libaries in the page, as shown below:
    <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
    <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
  3. In the Palette window, expand the JSF category. Click and drag the JSF Form entry into the desired location in the JSP file and release the mouse button.
  4. In the dialog box, select Form Generated from Entity Class and specify the full entity class name, including the package name. You can click Browse to search all classes in the project contents and classpath. Specify whether the form should be editatble or read-only and click OK.

    If you speficied a read-only form, the IDE enters the following code in the page:

    <f:view>
        <h2>Detail</h2>
        <h:form>
            <h:panelGrid columns="2">
                <h:outputText value="column1-title:"/>
                <h:outputText value="#{anInstanceOfclass-name.column1}" title="column1-title" />
                ...
            </h:panelGrid>
        </h:form>
    </f:view>

    If you speficied an editable form, the IDE enters the following code:

    <f:view>
        <h2>Create</h2>
        <h:form>
            <h:panelGrid columns="2">
                <h:outputText value="column1-title:"/>
                <h:inputText title="column1-title" value="#{anInstanceOfclass-name.column1}" 
    			    title="column1-title" />
            </h:panelGrid>
        </h:form>
    </f:view>
  5. Replace the anInstanceOfclass-name variable with a property in a JSF managed bean that refers to a single entry in the data source. Note that the JSF managed bean is often not the entity class itself but a separate controller class.
  6. The IDE generates an entry for each column of data to which the entity class provides access. Remove any of the entries for columns that you do not want to display in your JSP file.
See Also
About Web Application Frameworks
Adding JSF Support to an Existing Application
About CRUD Applications
Creating an Entity Class
Generating Persistent Entity Classes from a Database

Legal Notices