Hi Bob, Thnxs a lot. I used the Page#onRender to invoke the Table#getRowList as you said and worked fine.
Regards 2010/6/7 Bob Schellink <[email protected]> > Hi Manuel, > > On 8/06/2010 06:52, Manuel Chinea wrote: > > i have the following problem using paging dataproviders. If the > > PagingDataProvider.size() throws an Exception, the click servlet doesn't > > redirect to the configured error page. It looks like it sees the > > exception as some sort of parsing error (velocity?). It only redirects > > the exceptions thrown by the page lifecycle methods. I have put > > together a simple test case, like this: > > > Your conclusion is correct, once the HttpServletResponse starts writing > data to its output stream > Click cannot change the response to the ErrorPage. > > The fix would be to invoke Table#getRowList during the onRender event to > ensure any exceptions are > thrown *before* rendering the response. This can be done in the > Page#onRender or a custom > Table#onRender. > > I think this will be a good enhancement for the next release of Click. > > Kind regards > > Bob > > > > a.- IndexPage.java > > > > public class IndexPage extends Page { > > @Bindable > > public Table table = new Table("table"); > > > > public IndexPage() { > > table.setDataProvider(new PagingDataProvider() { > > public int size() { > > if (Math.random() > 0.5d) { //to simulate an exception > > throw new RuntimeException(); // (*1) > > } > > return 1; > > } > > > > public Iterable getData() { > > // TODO Auto-generated method stub > > ArrayList arrayList = new ArrayList(); > > arrayList.add(new Object()); > > return arrayList; > > } > > }); > > table.addColumn(new Column("hashCode")); > > } > > > > @Override > > public void onRender() { > > if (Math.random() > 0.5d) { > > throw new RuntimeException(); //(*2) > > } > > super.onRender(); > > } > > } > > > > b.- click.xml > > > > <click-app charset="UTF-8"> > > <pages package="xyz" autobinding="annotation"> > > <page path="/click/error.htm" classname="TheErrorPage" /> > > </pages> > > <mode value="debug" /> > > </click-app> > > > > > > c.- TheErrorPage.java > > > > public class TheErrorPage extends ErrorPage { > > > > } > > > > d.- /click/error.htm > > > > "this is an error page" > > > > e.- index.htm > > > > Hello, index page here...now with the table... > > > > $table > > > > -------------------------- > > > > > > > > When this code runs, and throws the RuntimeException() in (*1), the > > rendered page is the index page, but the table rendering prints a error > > box. But when the random value is lower than 0.5, the onRender is > > executed, and the RuntimeException() (*2) it throws, gets the click > > servlet to redirect to the error page. > > > > Is there any way to fix this? > > > > > > -- > > Manuel Chinea. > > -- Manuel Chinea.
