« Return to Thread: Trouble connecting custom data provider to a table

Trouble connecting custom data provider to a table

by TedByers :: Rate this Message:

Reply to Author | View in Thread

Java SE 6
NetBeans 6.0.1

All was going fine until this exercise in frustration.

In my package db, I created a custom data provider:

public class vacationDataProvider extends ObjectListDataProvider {
    private ArrayList vacationData = new ArrayList();

    public vacationDataProvider() {
        setList(vacationData);
        setObjectType(vacationRow.class);
    }
   
    public vacationDataProvider(String[][] data) {
        vacationData.clear();
        for (int i = 0 ; i < data.length ; i++) {
             vacationRow aNewRow = new vacationRow(data[i]);
             vacationData.add(aNewRow);
        }
        setList(vacationData);
        setObjectType(vacationRow.class);
    }
   
    public void load(long bid) {
        String[][] data;
        ResultSet rs = null;
        Connection con = null;
        try {
            con = db.ConnectionFactory.getConnection();
            CallableStatement vacation_cStmnt = con.prepareCall("{call get_vacations(?)}");
            vacation_cStmnt.setLong("bid", bid);
... (lots more boring JDBC code)

This class has only the one data member, two constructors and the load function.  I'd use a view, but the table should have only the data from the stored procedure (it selects the rows based on the single parameter, and we can't have a parameterized view).

The row class is equally simple (in my db package):
public class vacationRow implements java.io.Serializable {
    private static final long serialVersionUID = 4L;
    private int vacation_id;
    private java.sql.Date start_date;
    private java.sql.Date end_date;
   
    public vacationRow(){
    }

    public vacationRow(String[]  data){
        setVacation_id(Integer.parseInt(data[0]));
        setStart_date(java.sql.Date.valueOf(data[1]));
        setEnd_date(java.sql.Date.valueOf(data[2]));
    }
... + accessor functions for the data members.

The problem is that, whether I add the following code to the page bean or the session bean, I can't connect it to the table on the page.

I put the following at the end of init():

        theVacationDataProvider = new db.vacationDataProvider();
        theVacationDataProvider.load(1);

And I put the following at the end of the class:

    private db.vacationDataProvider theVacationDataProvider = null;

    public db.vacationDataProvider getTheVacationDataProvider() {
        return theVacationDataProvider;
    }

    public void setTheVacationDataProvider(db.vacationDataProvider theVacationDataProvider) {
        this.theVacationDataProvider = theVacationDataProvider;
    }

Yet, whether I put this in the session bean or in the page bean, when I go to bind this data provider to my table, using the visual design editor, the dialog that pops up does not seem to know that this data provider exists.  For that matter, BTW, it seems the dialog doesn't know that the session bean exists.

I am baffled because I have created dozens of JSF tables, and many of these have used custom data providers based on stored procedures, and I have never encountered this problem before.  How do I fix this?

Thanks

Ted

 « Return to Thread: Trouble connecting custom data provider to a table