ADF_Data Binding系列1_使用Bean Data Control

2015-02-16 Created By BaoXinjian

一、摘要


本文介绍通过JavaBean和ADF Faces开发一个数据显示Application

Step 1: Create a New Application and Project

Step 2: Create a Simple JavaBean Class

Step 3: Create a Service Class

Step 4: Create a Data Control for the Service Class

Step 5: Create a JSF Page

Step 6: Bind an ADF Faces Table Component to the Service Bean

Step 7: Set the Labels

Step 8: Bind to a Parameterized Method and a Parameter

 

1: Create a New Application and Project


Step1. 创建一个Custom Application

Step2.  查看说创建的Application

 

2: Create a Simple JavaBean Class


Step1.  创建一个JavaBean Class

Step2.  新增两个属性name/email,并自动产生他们的get/set方法

Step3.  查看所常见的Contact.java包

Step4.  查看Contace.java包对应的代码

package acme.bean;

public class Contact {
    public Contact() {
        super();
    }
    
    private String name;
    private String email;

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getEmail() {
        return email;
    }
    
    public Contact(String name, String email) {
       this.name = name;
       this.email = email;
     }
}

 

3: Create a Service Class


Step1.  创举一个Sevice Java Class

Step2. 定义包名等属性参数

Step3.  查看所创建的AddressBook.java包

Step4.  查看AddressBook.java包中的代码

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern; 
public class AddressBook {
   // Return all contacts
   List<Contact> contacts = new ArrayList();

  public List<Contact> findAllContacts() {
     return contacts;
   }

  // Return all contacts matching name (case-insensitive)
   public List<Contact> findContactsByName(String name) {
     String namePattern = ".*" + (name != null ? name.toUpperCase() : "") + ".*";
     List<Contact> matches = new ArrayList();
     for (Contact c : contacts) {
       if (Pattern.matches(namePattern, c.getName().toUpperCase())) {
 matches.add(c);
       }
     }
     return matches;
   }

   public AddressBook() {
     contacts.add(new Contact("Steve", "steve@acme.org"));
     contacts.add(new Contact("Charles", "cyoung@acme.org"));
     contacts.add(new Contact("Karl", "kheint@acme.org"));
     contacts.add(new Contact("Mik", "mik_meir@acme.org"));
     contacts.add(new Contact("Yvonne", "yvonne_yvonne@acme.org"));
     contacts.add(new Contact("Sung", "superstar001@acme.org"));
     contacts.add(new Contact("Shailyn", "spatellina@acme.org"));
     contacts.add(new Contact("John", "jjb@acme.org"));
     contacts.add(new Contact("Ricky", "rmartz@acme.org"));
     contacts.add(new Contact("Shaoling", "shaoling@acme.org"));
     contacts.add(new Contact("Olga", "olga077@acme.org"));
     contacts.add(new Contact("Ron", "regert@acme.org"));
     contacts.add(new Contact("Juan", "jperen@acme.org"));
     contacts.add(new Contact("Uday", "udaykum@acme.org"));
     contacts.add(new Contact("Amin", "amin@acme.org"));
     contacts.add(new Contact("Sati", "sparek@acme.org"));
     contacts.add(new Contact("Kal", "kalyane.kushnane@acme.org"));
     contacts.add(new Contact("Prakash", "prakash01@acme.org"));
   }
 }

 

4: Create a Data Control for the Service Class


Step1.  编辑AddressBook,Create Data Controls

Step2.  查看AddreesBook.java包中对对应的Data Controls结构

 

Thanks and Regards

 

posted on 2015-03-13 09:53  东方瀚海  阅读(762)  评论(0编辑  收藏  举报