Sun Java Studio Creator 2 – Online Help
 

Binding a List Component to an Enterprise JavaBean Method

See Also

When you bind a list component to an Enterprise JavaBean component (enterprise bean), you create a connection between them. List components display one or more values at a time. For easiest data binding, use components from the Basic category of the Palette, such as Listbox, Drop Down List, Checkbox Group, or Radio Button Group.

After you add the Enterprise JavaBean component to the IDE and to the page, you can call an enterprise bean method by using either of the following techniques:

The examples in the following procedures describe how to call the same method using both techniques.

To bind a list component to a method:

  1. If the enterprise bean is not part of the IDE, add the enterprise bean to the IDE.
     
  2. Drag and drop the method onto the component.
     
  3. Right-click the component and choose Bind to Data.
     
  4. In the Bind to Data dialog box, click the Bind to Data Provider tab.
     
  5. Choose the methodis data provider.
     
  6. Select the value field and display field for the component.
     
    For example, consider the following scenario. You want to use the getPersons method of the TravelEJB to display names in a drop-down list.
    1. Add the TravelEJB shipped with the IDE.
       
    2. Drag the Basic > Dropdown List component to the page.
       
    3. Drag the getPersons method onto the drop-down list.
       
    4. Right-click the drop-down list and choose Bind to Data.
       
    5. Select personid for the value field and name for the display field.
       

     

To call a method in your Java code:

  1. If the enterprise bean is not part of the IDE, add the enterprise bean to the IDE.
     
  2. If the enterprise bean has not been added to the page, drag it to the Visual Designer.
     
  3. If desired, select a method to see its properties in the Properties window.
     
  4. Call the method in your Java code.
     
    For example, consider the following scenario. You want to use the getPersons method of TravelEJB to display names in a drop-down list.
     
    1. Drag the Basic > Dropdown List component to the page.
       
    2. Drag the getPersons method of TravelEJB to the page.
       
    3. In the Projects window, add a property named personOptions with the type ArrayList.
       
      • In the Projects window, expand project-name > Source Packages > web application-name.
         
      • Right-click Page1.java and choose Add > Property.
         
      • In the New Property Pattern dialog box, enter personOptions in the Name field and enter ArrayList in the Type drop-down list.
         
    4. Go to the Page1.java source code by selecting the Java tab.
       
    5. In the init() method, enter the following code:
       
    6. personOptions = new ArrayList();
      
              
      
       try {
      
           PersonDTO[] persons = travelClient1.getPersons();
      
           for( int i = 0; i < persons.length; i ++ ) 
      
               personOptions.add( new Option(new Integer(persons[i].getPersonId()), persons[i].getName() ) );
      
           
      
       }catch (Exception e) {
      
           log("Page1 Initialization Failure", e);
      
           throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
      
       }
    7. Right-click in the Java Editor and choose Fix Imports.
       
    8. In the Fix Imports dialog box, choose com.sun.rave.web.ui.model.Option.
       
    9. Bind the new property to the drop-down list.
       
      • In the Visual Designer, right-click the drop-down list and choose Property Bindings.
         
      • In the right list in the Property Bindings dialog box, select Page 1 > personOptions.
         
      • Click Apply, then click Close.
         
See Also
About Enteprise JavaBean Components
Adding a Set of Enterprise JavaBean Components to the IDE
About the Projects and Files Windows
About the Java Editor
 
 
 
Legal Notices. Copyright © 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Close