Search code examples
javadatagriderror-handlingtapestry

error tapestry using data gridsource 2


Continuing tutorial I have came across an error. previous problem seems to be fixed.

tutorial says: To make use of the created CelebritySource, add the following method to the ShowAll page class:

public GridDataSource getCelebritySource()
{
return new CelebritySource(dataSource);
}

Then change the source parameter of the Grid component in ShowAll.tml template:

<t:grid t:source="celebritySource" rowsPerPage="5"
row="celebrity" t:model="model">

Run the application. Log in to view the ShowAll page, and as soon as the table with celebrities is displayed, you should see the following output:

Preparing selection. Index from 0 to 4 Property name is: null Sorting order ascending: true Getting value for row 0 Getting value for row 1 Getting value for row 2 Getting value for row 3 Getting value for row 4

page has error:

An unexpected application exception has occurred.

Exception assembling root component of page ShowAll: Could not convert 'model' into a component parameter binding: Exception generating conduit for expression 'model': Class org.apache.tapestry.pages.ShowAll does not contain a property (or public field) named 'model'.

After deleteing t:model="model" from t:grid

page has error:

An unexpected application exception has occurred.

Render queue error in SetupRender[ShowAll:grid]: Index: 0

Anyone out there had this problem?


Solution

  • Seems the example was missing a bit of code. Try adding the following to the page ShowAll.java:

    @Inject
    private BeanModelSource beanModelSource;
    
    @Inject
    private Messages messages;
    
    public BeanModel<Celebrity> getModel() {
      return beanModelSource.createDisplayModel(Celebrity.class, messages);
    }
    

    From the T5 Grid Component Ref:

    The model used to identify the properties to be presented and the order of presentation.

    The above should create you a default BeanModel, based on public methods and properties.