It's not working at all and I'm getting close to running screaming from the
building.  Following is more code.  It is the current state of affairs. 
With the code as displayed I get this error:

> Failure reading parameter 'model' of component
> misc/DataTableDemo:datatable: Unable to determine the bean type for rows
> from org.apache.tapestry5.internal.grid.NullDataSource@187a72d9. You
> should bind the model parameter explicitly.

It looks to me like that is a result of it not knowing what class type to
use to display records.  I would have thought that /t:row="current"/ and
it's associated plumbing would have taken care of that.  Or, calling
/getRowType()/ method, which is returning a class, should solve that
problem.

Further, it looks like NullDataSource is used when it can't find my defined
datasource.  This also doesn't make sense to me as it is defined in the tml
and java.

If I add /t:model="model"/ and some java code associated with that to create
a BeanModel I don't get any errors, but /prepare()/ is not called an queries
are not run.

So, here's the code.  Thank you in advance for your help (and talking me
down from the ledge).

DataTableDemo.tml:
<t:jquery.datatable id="dataTable" t:row="current" t:mode="true"
t:source="celebrityService" 
                    rowsPerPage="5" exclude="id"
reorder="lastName,firstName,occupation,DOB" options="initParams">
</t:jquery.datatable>

DataTableDemo.java
public class DataTableDemo {
    @Property
    private CelebrityService celebrityService;

    @Property
    @Environmental
    private Celebrity current;

    public JSONObject getInitParams(){
        //snipped
    }
    
    void setupRender() {
        if (celebrityService == null)
            celebrityService = new CelebrityService();
    }
}

CelebrityService.java
public class CelebrityService implements GridDataSource {
    private SqlSessionFactory sqlSessionFactory;
    private List<Celebrity> preparedResults;
    private int startIndex;
    
    public CelebrityService() {
        sqlSessionFactory =
MyBatisConnectionFactory.getSqlSessionFactory();;
    }

    @Override
    public int getAvailableRows() {
        SqlSession session = sqlSessionFactory.openSession();
        int count;
        try {
            CelebrityMapper mapper =
session.getMapper(CelebrityMapper.class);
            count = mapper.count();
        } finally {
            session.close();       
        }
        return count;
    }

    @Override
    public void prepare(int startIndex, int endIndex, List<SortConstraint>
sortConstraints) {
        List<SortCriterion> sortCriteria = toSortCriteria(sortConstraints);
        this.startIndex = startIndex;
        
        SqlSession session = sqlSessionFactory.openSession();
        try {
            CelebrityMapper mapper =
session.getMapper(CelebrityMapper.class);
            preparedResults = mapper.selectAll();
        } finally {
            session.close();       
        }
    }

    private List<SortCriterion> toSortCriteria(List<SortConstraint>
sortConstraints) {
        System.out.println("CelebrityService toSortCriteria()");
        List<SortCriterion> sortCriteria = new ArrayList<SortCriterion>();

        for (SortConstraint sortConstraint : sortConstraints) {

            String propertyName =
sortConstraint.getPropertyModel().getPropertyName();
            SortDirection sortDirection = SortDirection.UNSORTED;

            switch (sortConstraint.getColumnSort()) {
            case ASCENDING:
                sortDirection = SortDirection.ASCENDING;
                break;
            case DESCENDING:
                sortDirection = SortDirection.DESCENDING;
                break;
            default:
            }

            SortCriterion sortCriterion = new SortCriterion(propertyName,
sortDirection);
            sortCriteria.add(sortCriterion);
        }

        return sortCriteria;
    }
    
    @Override
    public Object getRowValue(int index) {
        return preparedResults.get(index - startIndex);
    }

    @Override
    public Class<Celebrity> getRowType() {
        return Celebrity.class;
    }
}




--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/ANN-JumpStart-gets-jQuery-DataTables-example-tp5715816p5719422.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to