You will use wizards to quickly create an application and a project, and a blank JSF page. To create a simple bean object you will generate a starter Java class, then use the source editor to add two String properties and getter and setter methods on the properties. You will also add a business method to save input data and display a console message using the data.
show more or lessRead more...

Next you will register the Java class as a managed bean in faces-config.xml. Then you will design a simple UI using two input text fields and a button, and bind the input fields and button to the managed bean using JSF EL Expressions. Finally you will hook up the button to a method in the managed bean that will invoke the business method when the button is clicked. When you test run the page, the page in the browser will look like this:

Browser, registration form

Purpose Duration Application
This tutorial shows you how to create a simple bean object and use the bean in a JSF application. To see the complete application you will create, click the Download button to download a zip of the final application, and then unzip it in your JDeveloper mywork folder. 20 minutes Download jsfbeanapp.zip
Step 1: Create a New Application and Project
  1. From the main menu, choose File > New. In the New Gallery, expand the General category and select Applications. Then in the Items list, select Custom Application and click OK.

    New Gallery, Applications
  2. The JDeveloper application is the highest level in the organizational structure. While you are developing your application, it stores information about the objects you are working with. Show more or lessRead more... At the same time, it keeps track of your projects and all environment settings.

    Based on prebuilt templates, a JDeveloper application allows you to specify a predefined type of environment, depending on the type of application you want to create (web application, Java application, and so on). Application templates provide you with a quick way to create the project structure for standard applications with the appropriate combination of features already specified. The application template also filters the work you do in JDeveloper such that the choices available are focused only on the features you are working with.

    In this tutorial, you will use the Custom Application template, which makes available objects associated with all the features that JDeveloper supports in a single project.

    Once you have created an application using a suitable template, you can still add new projects to the application and specify what features are to be included. To do this, in the Application Navigator, right-click the application name and choose New Project. In the New Gallery, you can select any type of project in the Items list.
  3. To follow along with the example, enter JSFBeanApp as the application name.

    Create generic application
  4. The application template you select determines the initial project structure, that is, the named project folders within the application workspace, and the application libraries that will be added. Show more or lessRead more... The project or projects in the application define the associated features.

    A JDeveloper project, which is used to logically group files that are related, keeps track of the source files, packages, classes, images, and other elements that your program may need. Projects manage environment variables such as the source and output paths used for compiling and running your program. Projects also maintain compiler, runtime, and debugging options so that you can customize the behavior of those tools per project.

    You can add multiple projects to your application to easily access, modify, and reuse your source code. Different projects might contain files representing different tiers of a multi-tier application, for instance, or different subsystems of a complex application. These files can reside in any directory and still be contained within a single project.
  5. Accept the defaults and click Finish.

    The Projects panel in the Application Navigator should look like this:

    Application Navigator, Projects panel

  6. A new application created from a template appears in the Application Navigator already partitioned into tiered projects, with the associated features set in each project. Show more or lessRead more... Projects are displayed as the top level in the hierarchy in the Application Navigator. The Custom Application template that you used for your application creates one project using a default project name (or the project name you entered).

    In the Application Navigator you can collapse and expand any panel. You adjust the size of panels by dragging the splitter between two panels. To group and sort items in the Projects panel, use the navigator display options icon Navigator Display Options dropdown menu. For application operations, you can click application icon Application Menu and choose an option from the dropdown menu.

    JDeveloper has the capability of recognizing many different file types, displaying each in its appropriate viewer or editor when you double-click the file in the Application Navigator. Closing an application or project closes all open editors or viewers for files in that application or project and unloads the files from memory.

    Note: Nodes in italics in the Application Navigator mean that the elements have not yet been saved. A project node is bold when a file in the project is selected.

    From the main menu, choose Application > Show Overview. The Application Overview window opens in the editor window area.

    Part of Application Overview window

    All objects that you create within JDeveloper appear in the Application Overview file summary pages, arranged by object type. As you create new files and artifacts, you can view them filtered by status and project.

    You can optionally close the Application Overview window, since you will not be using it to create objects for this application.
Step 2: Create a JSF Page
  1. In the Application Navigator, right-click the project and choose New > Web Tier > JSF/Facelets > Page, then click OK.

    new gallery, web tier

  2. In the Create JSF Page dialog, enter Register.jsf as the file name. Make sure Facelets is the selected document type.

    Create JSF Page dialog
  3. The JSF pages you create for your application using JavaServer Faces can be Facelets documents (which have file extension .jsf) or JSP documents written in XML syntax (which have file extension .jspx). Show more or lessRead more...

    You can create both types of JSF pages with the Create JSF Page dialog, opening it from:
    • The New Gallery

    • The JSF navigation diagrammer

    • The ADF task flow diagrammer (available only in the Studio edition of JDeveloper)

  4. On the Page Layout page, select Blank Page. On the Managed Bean page, select Do Not Automatically Expose UI Components in a Managed Bean.

  5. In the Create JSF Page dialog, you can optionally define some aspects of the look and feel for the new page, and you can specify whether or not components on the page are exposed in a managed bean, to allow programmatic manipulation of the UI components. Show more or lessRead more...

    By default components are not exposed to managed beans. If you wish to bind components to managed beans, select one of the automatic binding options on the Managed Bean page in the dialog.

    Create JSF Page dialog, Managed Bean tab

    Note: The option to bind to an existing managed bean is enabled only if the application has a managed bean already configured.

    If you choose to automatically expose UI components in a managed bean, JDeveloper automatically creates a backing bean for any new JSF page that you create. When you drop a component on the page, JDeveloper inserts a bean property for each component, and uses the binding attribute to bind component instances to those properties, allowing the bean to accept and return component instances.

    If you choose not to let JDeveloper use automatic component binding at page creation time, you can use the Property Inspector to manually bind any component on the page. For example, if you insert an input text component, click the dropdown menu icon dropdown menu at the end of the component's Binding field in the Property Inspector and choose Edit. Then in the Edit Property dialog, you can create a managed bean for the page if one does not already exist.

    Property Inspector, Binding property, Edit
  6. Click OK.

    By default JDeveloper displays the new JSF Facelets page in the visual editor.

    Visual editor, Component Palette

  7. The tabs at the top of the editor window are the document tabs. Selecting a document tab gives that file focus, bringing it to the foreground of the window in the current editor. Show more or lessRead more... The tabs at the bottom of the editor window for a given file are the editor tabs. Selecting an editor tab opens the file in that editor or viewer. For example, to switch from the visual editor to the XML editor, select the Source tab.

    When you create a new JSF page as a Facelets document type (with file extension .jsf), JDeveloper automatically creates a starter page structure with two xmlns attributes for the JSF Core and JSF HTML tag libraries. The other elements included in a starter file are elements for laying out a page, specifically everything else within <f:view> and </f:view>. For example, the following code is generated for the new page:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <f:view xmlns:f="http://java.sun.com/jsf/core"
            xmlns:h="http://java.sun.com/jsf/html">
      <html xmlns="http://www.w3.org/1999/xhtml">
        <h:head>
          <title>Register</title>
        </h:head>
        <h:body>
          <h:form></h:form>
        </h:body>
      </html>
    </f:view>
    When you complete the steps for creating a JSF page, the Application Navigator should look something like this:

    Application Navigator, JSF page

    In the project, the folders and files that conform to the Java EE Web module directory structure are:
    • Web Content folder: Contains the pages you create, along with other files that must be visible to the client browser (such as stylesheet files and images) for your application.

    • /WEB-INF/ folder: Contains the required Web Application Deployment Descriptor (web.xml) and the JSF configuration file (faces-config.xml).

    • web.xml file: The web application deployment descriptor for your application. This is an XML file describing the components that make up your application, along with any initialization parameters and container-managed security constraints that you want the server to enforce for you.

    • faces-config.xml file: Where you register the JSF application's configuration resources, such as validators, converters, managed beans, and navigation rules.

Step 3: Create a Java Class
  1. In the Application Navigator, right-click the project you just created and choose New > General > Java Class, then click OK.

    New Gallery, General category items

  2. In the Create Java Class dialog, enter the class name as PersonInfo. Accept the default values and click OK.

    Create Java Class dialog

  3. In the source editor, add code to create a simple JavaBean object.

    For example, after the generated code:

    public PersonInfo() {
      super();
    }


    Add two properties by using the following code:

  4. In JSF, you send and display dynamic data by binding UI components or component attribute values to data in the model layer. This data can be held in any JavaBean within the application. Show more or lessRead more...

    The example you are creating requires a user to enter data in two fields and then click a button to display a message. To capture the data, you need to add two properties and create getter and setter methods on the properties. Later you will add a method to save the input data and display a message using the data.
  5. Right-click the file in the editor and choose Generate Accessors.

    Java source editor, Generate Accessors
  6. In the source editor, other features available to you while you're editing include: Show more or lessRead more...
    • Java Code Insight, the Java-specific implementation of completion insight

    • fix icon Code Assist to fix common problems

    • Import statement assistance and sorting

    • Automatic doc comment templates

    • Customizable sorting and expansion for the Structure window

    • Distinctive highlighting for syntax and semantic errors

    • Customizable code separators

    Press F1 in the source editor if you want to learn more about these features.
  7. In the Generate Accessors dialog, select PersonInfo. Make sure public is selected in the Scope dropdown list, then click OK.

    Generate Accessors dialog

  8. In the source editor, add code to retrieve the data that is entered and then display a message using the data.

    For example, after the generated method:

    public String getEmail() {
      return email;
    }


    Add the following method:

  9. Click saveall icon Save All to save your work.

    In the Application Navigator, you should see PersonInfo.java in the project1 package in the Application Sources folder.

    Application Navigator, project1 package
  10. When developing a real application in JDeveloper, you will need to consider how to persist data in a meaningful and efficient way. Show more or lessRead more... You may also encounter situations where using a simple JavaBean for the data model is not sufficient, or you may need to aggregate data from a variety of sources. In these cases, you can work with data sources based on entirely different business service technologies, for example:
    • Oracle ADF Business Components (available only in the Studio edition of JDeveloper)

    • Enterprise JavaBeans (EJB)

    • Oracle TopLink, which helps to map your Java classes and EJBs to database tables.

    Web services, as an alternative to the above business services when you don't need to create the back-end business service but want to expose existing business services (including EJB components, stored procedures in the database, or other business services written in Java or any other language).

    Whether you use JSF with JavaBeans, Enterprise JavaBeans (EJB), Oracle TopLink, or Web services in the model layer, JDeveloper's productive coding and data binding tools enable you to implement the application back end and integration code safely and easily. To work with a specific business service, you can open the New Gallery and use the provided wizards and dialogs to create or, in the case of web services, expose the entities in your model project.
Step 4: Register the Class as a Managed Bean
  1. In the Application Navigator, double-click faces-config.xml to open it in the editor window.

  2. Your application needs certain resources, such as files containing the messages and text to be displayed by the application pages, and beans defining the data for the application to work with. Show more or lessRead more...

    The resources your application needs are specified in the JSF configuration file, faces-config.xml. The resources an application might need include:

    • Managed beans

    • Custom message bundles

    • Custom validators and converters

  3. Select the Overview tab at the bottom of the editor window to use the overview editor.

    By default the Managed Beans page is shown on the overview editor.

    Overview editor for JSF configuration file
  4. Managed beans are any JavaBeans used by the application that are registered in the JSF configuration file faces-config.xml. Show more or lessRead more... At any time, you can add managed beans to the faces-config.xml file by either editing the XML in the file manually, or using an overview editor for configuration files, which provides creation dialogs and browse features for finding class file references for your beans.

    To define a managed bean in faces-config.xml, you add an entry to the JSF configuration file, giving a symbolic name that you will use to refer to the bean and specifying the class to be used to instantiate the bean. You use the symbolic name to identify the bean when you need to refer to the bean's properties and methods. Because you are using a symbolic name rather than referring to the bean directly, the presentation is kept separate from the application logic, which means that you can change the model without affecting the view.
  5. Click add icon to open the Create Managed Bean dialog. Enter personData as the bean name. Then click the browse icon next to the Class Name field to open the class browser.

    Create Managed Bean dialog

  6. Enter PersonInfo in the field and then select PersonInfo (project1). Click OK to close the class browser.

    Class Browser

  7. In the Create Managed Bean dialog, select Configuration File. Then verify you now have the following values entered or selected:

    Field or Option Value
    Bean Name PersonData
    Class Name PersonInfo
    Package project1
    Extends java.lang.Object
    Scope request
    Registration Configuration File
    Generate Class If It Does Not Exist selected
  8. The scope of a managed bean determines the scope within which the bean is stored. The following are the valid scopes for a bean: Show more or lessRead more...
    • application: The bean is available for the duration of the web application. This is helpful for global beans such as LDAP directories.

    • session: The bean is available to the client throughout the client's session.

    • request: The bean is available from the time it is instantiated until a response is sent back to the client. This is usually the life of the current page.

    • none: The bean is instantiated each time it is referenced. This is helpful if the bean is referenced within another bean.

    In JSF 2.0, you have the option of using managed bean annotations in the bean class instead of registering managed beans in faces-config.xml. Using managed bean annotations reduces the size and complexity of the faces-config.xml file, which can grow quite substantially. When you use annotations, instead of adding a <managed-bean> element in faces-config.xml JDeveloper adds the annotations @ManagedBean and @RequestScope in the JavaBean class file. For example:

    @ManagedBean(name="backing_mypage")
    @RequestScoped
    public class MypageInfo {
      ...
    }
  9. Click OK.

    You should see the new managed bean definition in the overview editor:

    Overview editor for JSF configuration file, managed bean

  10. When you use the overview editor for faces-config.xml to configure a managed bean, JDeveloper automatically updates the faces-config.xml file for you with the necessary configuration elements. Show more or lessRead more...

    For example:

    <managed-bean>
      <managed-bean-name>personData</managed-bean-name>
      <managed-bean-class>project1.PersonInfo</managed-bean-class>
      <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>


    When the JSF application starts up, it parses faces-config.xml and the managed beans are made available. Whenever a managed bean is referenced (for example in an EL expression as a value for a component's tag attribute - called a value expression), the Managed Bean Creation Facility instantiates the bean by calling the default constructor method on the bean. If any properties are also declared, they are populated with the declared default values.
Step 5: Design the UI
  1. In the editor window, select the Register.jsf tab at the top to bring the page forward.

  2. When designing a page in the visual editor, you can use the breadcrumb links at the bottom of the editor window (just above the editor tabs Design and Source) to select an existing component or tag on the page. Show more or lessRead more...

    Visual editor

    The editor breadcrumb links show the path of links from the currently selected component or tag back to its root parent component or tag.

    When you click a component or tag in the editor breadcrumb links, JDeveloper shows the selected component or tag on the page with a dropdown menu icon at the top right corner of the selected item. When you click the dropdown menu, JDeveloper displays a context menu of actions that you can perform on the selected component or tag. For example:

    Visual editor, JSF page

    The visual editor is also fully integrated with the Structure window. While inserting, copying, or moving JSF components, you may select an insertion point on the page in the visual editor or in the Structure window in relation to a target page element. JDeveloper provides visual cues to indicate the location of the insertion point before, after, or contained inside a target component.

    After inserting components, you can set the properties of the components either using a dialog displayed at the time you drop the component, if one is required, or later using the Property Inspector.

    Your application pages can also use a style sheet, either one provided by JDeveloper or one of your own. You can add a style sheet to a page at the time you create it, or later, by editing the page. If you have added a style sheet to your page, you can set the text on the page, such as the heading text, to a style chosen from the dropdown list:

    Style dropdown list in visual editor toolbar
  3. In the visual editor, type the text Registration Form at the top of the page.

    Visual editor
  4. By default, JDeveloper does not automatically create text resources in the page's resource bundle when you edit UI components in the visual editor. Show more or lessRead more... If you wish to use a resource bundle, select the Automatically Synchronize Bundle option in the Project Properties dialog, Resource Bundle page. The default bundle type is Properties Bundle, which is a PropertyResourceBundle properties file or a plain-text file containing translatable text. A properties file can contain values only for String objects. If you need to store other types of objects, use a ListResourceBundle instead.

    Project Properties, Resource Bundle

    When Automatically Synchronize Bundle is selected, after you enter text in the visual editor and press Enter, JDeveloper displays the text as an EL expression:

    Visual editor, EL expression

    JDeveloper also creates the properties file. For example:

    #
    SOME_TEXT=Some Text
  5. In the Component Palette, select the HTML page from the dropdown list and then expand the Common panel.

    HTML components in Component Palette
  6. JDeveloper provides the Component Palette to drag and drop components onto your JSF pages in the visual editor. Show more or lessRead more...

    Help information is provided for each component, explaining its purpose and its attributes. To find such information, right-click an item in a panel in the Component Palette and choose Help.
  7. Click and drag table icon Table to the visual editor, then drop it on the page to add a table.

  8. In the Insert Table dialog, set the number of rows to 3 and the number of columns to 2. Accept the other default values and click OK.

    Insert Table dialog

  9. In the Component Palette, select the JSF page from the dropdown list and then expand the HTML panel.

  10. Facelets uses the concept of XML namespaces to support JSF tag libraries. The libraries that provide the JSF components are: Show more or lessRead more...
    • The JavaServer Faces HTML tag library, which contains tags representing common HTML user interface components.

    • The JavaServer Faces Core tag library, which contains tags that perform core actions such as event handling and data conversion.

    JSF components in Component Palette
  11. Drag and drop input text icon Input Text on the first row, second column of the table.

    Visual editor
  12. Tables can be used to design page layout, as in this example, as well as to lay out data, and position text and graphics on a web page. Show more or lessRead more...

    The Insert Table dialog helps you to add the HTML <table> element and set up the initial properties in the skeleton table. After inserting the skeleton table, you will use the Component Palette and visual editor to design the registration form by adding input fields and labels.

    You can also easily modify both the appearance and the structure of the table using the visual editor. You can edit tables to add text and images; add, delete, resize, reorder, split, and merge rows and columns; modify table, row, or cell properties for color and alignment; copy and paste cells; and nest tables in table cells.

    To modify all or part of a table in the visual editor, first select the table, rows, columns or cells. To select:
    • The entire table, place the cursor at the bottom right corner of the table border, and click when the table selector icon table selector icon appears.

    • Rows, place the cursor on the left border of the table and click when the row selector icon row selector icon appears.

    • Columns, place the cursor on the top border of the table, and click when the column selector icon column selector icon appears.

    • Cells, click in a single cell or press Ctrl and click in multiple cells.

    When you select a table in the visual editor, blue resize handles appear at the bottom and right sides, and in the bottom right corner of the table, as shown in the illustration earlier.

    To resize a table:
    • Drag the resize handles resize handles to the desired size for the table.

    To change the size of rows or columns:
    • Place cursor at the border of the row or column you wish to resize, and click when the horizontal border handle icon horizontal border handle or vertical border handle icon vertical border handle appears.

    To set properties for a selected table or cell using the visual editor toolbar:

    Visual editor toolbar
    • Click fill icon Background Color to apply a color to the table, row, or cell in the selected color.

    • Click leftalign icon centeralign icon
  rightalign icon Left Center Right to apply the respective left, center or right alignment to a selected table.

    • Click indent icon Indent or Outdent to indent or remove indentation from the selected table by applying or removing the <blockquote> tag.

  13. Drag and drop another input text icon Input Text on the second row, second column.

  14. Drag and drop command button icon Command Button on the third row, second column. In the Property Inspector, Common section, click in the Value field and change the default text to Sign Me Up.

  15. While working with standard JSF components in JDeveloper, you can view and set component tag attributes in the Property Inspector. Most of the standard JSF component tag attributes accept value expressions, that is, #{expression} using JSF Expression Language (EL). For example, #{personData.username}. Show more or lessRead more...

    When you add a component to the JSF page, the Property Inspector displays the supported attributes for the component tag grouped in these categories:
    • Common: Commonly used attributes, which varies from component to component. Also includes the attributes id and binding. The id is the unique identifier of a component, which must be a valid XML name; you cannot use leading numeric values or spaces in the id name. The binding is the EL expression that binds a component instance to a property in a bean.

    • Appearance: Basic attributes that control the visible parts, including title and accessKey.

    • Style: HTML style and presentation attributes such as background, border, cellpadding, cellspacing, font, margin, style, and outline. Most of the attributes that the HTML 4.01 specification declares for corresponding HTML elements are supported.

    • Behavior: Basic attributes that control the component's behavior, including HTML pass-through attributes such as disabled and readOnly. Also includes an Internationalization section for HTML language translation attributes such as lang and dir.

    • JavaScript: HTML event attributes (for associating client-side scripts with events) such as onclick, onkeypress, and onmouseover.

    To see descriptive information about a component's attribute, right-click in the property name or field in the Property Inspector. A resizable popup window appears, where you can view a description of the property in a scrollable Property Help box. You can also open the property popup window by clicking the dropdown menu icon dropdown menu.

    Property Inspector
  16. In the visual editor, click in the table cell of the first row, first column, and type Username:. Then type Email: in the cell of the first column, second row.

    The visual editor should now look similar to the following:

    Visual editor, table
Step 6: Bind the UI to the Managed Bean
  1. In the visual editor, select the first input text field. Then in the Property Inspector, Common section, choose Expression Builder from the property menu icon dropdown menu next to the Value field.

    Property Inspector
  2. In a previous step you created a JavaBean with two properties, username and email, and registered the bean as a managed bean. Show more or lessRead more... By registering the bean as a managed bean, at runtime the JSF application automatically instantiates the bean on demand, when the bean is accessed through an expression language (EL) expression from a page for the first time. Property values on the bean can then be displayed, and can also be updated when data from the page is submitted.

    Bean properties can be bound to component values or component instances. In the example, you will bind the bean properties to component values using the Expression Builder.
  3. In the Expression Builder, expand JSF Managed Beans, then expand personData. Select username to create an expression using the username variable. Then click OK.

    Expression Builder
  4. Introduced in Java EE 5.0 and JSP 2.1, the unified expression language (EL) is a union of the expression language offered by JSP 2.0 and the expression language created for JSF technology 1.0. Show more or lessRead more... The unified EL continues to let page authors use EL expressions to bind UI component values and objects to backing bean properties or reference backing bean methods from UI component tags.

    Two kinds of expressions are defined in the unified EL: value expressions and method expressions. Value expressions allow both getting and setting data on external objects through bean properties, and can reference lists, maps, arrays, implicit objects, and resource bundles. Method expressions reference methods that handle component events, or validate or convert component data.

    Value Expressions

    The syntax for value expressions follows that same syntax used by JSP 2.0 expression language. Examples of value expressions follow:
    • #{foo}

    • #{foo.bar}

    • #{foo.bar.baz}

    • #{foo[bar]}

    • #{foo["bar"]}

    • #{foo[3]}

    • #{foo[3].bar}

    • #{foo.bar[3]}

    • #{foo.bar == "Hello World"}

    • #{(foo.bar) / 5 * 3}

    • Offer Valid from #{offer.validFromDate} to {offer.validToDate}

    Method Expressions

    Method expressions must use one of the following patterns:
    • #{expression.value}

    • #{expression[value]}

    The expression can be any EL expression as described earlier for value expressions; the value must be an identifier that matches a method name on the object in the expression.

    Operators

    Expression language provides the following operators, in addition to the . and [] operators:
    • Arithmetic: +, - (binary), *, / and div, % and mod, - (unary)

    • Logical: and, &&, or, ||, not, !

    • Relational: ==, eq, !=, ne, <, lt, >, gt, <=, ge, >=, le. Comparisons can be made against other values, or against boolean, string, integer, or floating point literals.

    • Empty: The empty operator is a prefix operation that can be used to determine whether a value is null or empty.

    • Conditional: A ? B : C. Evaluate B or C, depending on the result of the evaluation of A.

  5. Repeat the procedure on the second input text field, selecting the email variable in the Expression Builder this time.

  6. In the visual editor, double-click the command button to open the Bind Action Property dialog. In the Managed Bean dropdown list, select personData.

    Bind Action Property dialog
  7. Earlier you used the Expression Builder to create the EL expressions for binding the input text components' value attributes to the bean properties. The command button component can be bound to methods in JavaBeans. Show more or lessRead more...

    The Bind Action Property dialog enables you to bind the button's action attribute to a new method that you will create next in the JavaBean.
  8. Accept the default values in the dialog and click OK.

    JDeveloper displays the Java class file in the editor window, showing the code added for you when you bound the command button component:

    Source editor after binding button
  9. In the visual editor of the Register.jsf page, if you click Source to switch to the XML editor, Show more or lessRead more... you should see value and method EL expressions in the input text and command button components code. For example:
    <h:inputText value="#{personData.username}"/>
    <h:inputText value="#{personData.email}"/>
    <h:commandButton action="#{personData.commandButton_action}".../>
Step 7: Finish the Code and Run the JSF Page
  1. If necessary, select the PersonInfo.java tab in the editor window to bring the source editor forward.

  2. In the generated action method, add code to call the business method saveInfo that you previously added to the bean.

    Recall that the saveInfo method takes two parameters and writes the data to the console. So for example, after the comment line in the generated code:

    // Add event code here...

    Insert the following code shown in bold:

  3. In the Application Navigator, right-click Register.jsf and choose Run.

    If the Create Default Domain dialog displays, enter the default password, for example weblogic1, in the Password and Confirm Password fields, then click OK.

    The page in the browser should look similar to this:

    Register page in browser

  4. By default, JDeveloper automatically configures an integrated server named Integrated WebLogic Server that references a user-specific instance of Oracle WebLogic Server bundled with the IDE. Show more or lessRead more... Integrated WebLogic Server is a Java EE runtime service for packaged archive deployment. Based on zero-copy deployment, Integrated WebLogic Server lets you run and test an application and its projects as a Java EE application in a Java EE container. No special connection setup is required to use Integrated WebLogic Server. You can run the entire application, a project, or individual JSF pages.

    When you run a JSF application in the IDE, JDeveloper automatically:
    • Starts Integrated WebLogic Server, if not already running.

    • Compiles and deploys the application to Integrated WebLogic Server.

    • Launches the application in your default browser using the following default address: http://<your_machine_IP_address>:<http_port>/<your_application_name>-<your_project_name>-context-root>/faces/<path_to_the_page>

      For example: http://127.0.0.1:7101/JSFBeanApp-Project1-context-root/faces/Register.jsf

    When you enter a username and an email address in the input fields, and then click the button:

    Register page in browser

    ...the data you entered will be written to the Log window in JDeveloper. For example, if you entered guest and guest@oracle.com, you should see the following message at the bottom of the Log window:

    saving...guest guest@oracle.com

    To stop the application, click terminate icon Terminate in JDeveloper and choose the application bound instance JSFBeanApp from the dropdown menu.

    Note: Terminating the application stops and undeploys the application from Integrated WebLogic Server but it does not terminate Integrated WebLogic Server.
Summary
In this tutorial you created a simple application using JSF data binding. You learned how to: To learn more about developing JSF web applications, refer to:

Bookmark Print Expand all | Hide all
Back to top

Did you find this page helpful?



Copyright © 2011, Oracle and/or its affiliates. All rights reserved.