You can also catch exceptions on higher level than only a page and then decide which page to show, I mean wherever you would like to show a usual page or your page. It is reasonable in case you still want to see very nice internal exception page in case of unexpected exceptions, and you can see your own user friendly page in case of expected exceptions. You can add to the hivemodule.xml following code:
<!-- New Exception Presenter - customize exception pages --> <implementation service-id="tapestry.error.ExceptionPresenter"> <invoke-factory> <construct class="com.nokia.oss.sjrtpg.util.CustomExceptionPresenter"> <set-object property="exceptionPageName" value="infrastructure:exceptionPageName"/> <set-object property="requestExceptionReporter" value="infrastructure:requestExceptionReporter"/> <set-object property="responseRenderer" value="infrastructure:responseRenderer"/> </construct> </invoke-factory> </implementation> Then implement an exception presenter, like: public class CustomExceptionPresenter extends ExceptionPresenterImpl ... ... if( checkCause(cause, AccessControlException.class) || ( cause.toString() .indexOf("permission must be assigned for this operation") >= 0 ) ) { log.warn("Uncatched accessControlException", cause); cycle.activate("AuthorizationError"); try { renderer.renderResponse(cycle); return; }catch( IOException e ) { log.error("Error when rendering error page", e); } } if (checkCause(cause, PageRedirectException.class)) { log.warn("Page redirect exception", cause); cycle.activate("Home"); try { renderer.renderResponse(cycle); return; }catch( IOException e ) { log.error("Error when rendering error page", e); } } super.presentException(cycle, cause); Where checkCause checks wherever in the current exception causes presents given exception class. On 03/12/06, Cyrille37 <[EMAIL PROTECTED]> wrote:
Hello, I'm still learning Tapestry, and generally Java Web Application ... Now I can understand a beat about Tapestry and create little working project. Here is the time for me to learn how to manage errors, like trapping an underground exception in the view layer. The following example is from the "Kent Tong 's book" source code: the "shop" example. There is a page to view shop's products details: ProductDetails(.html,.page,.java). In ProductDetails.java there are accessors for a product details like : public String getName() { return lookup().getName(); } public String getDesc() { return lookup().getDesc(); } public double getPrice() { return lookup().getPrice(); } The lookup method to get a Product is : private Product lookup() { return Catalog.getGlobalCatalog().lookup(getProductId()); } In ProductDetails.page there are components like : <component id="name" type="Insert"> <binding name="value" value="name"/> </component> <component id="desc" type="Insert"> <binding name="value" value="desc"/> </component> <component id="price" type="Insert"> <binding name="value" value="price"/> </component> How can I catch an exception throwed by Catalog.getGlobalCatalog().lookup(getProductId()) when a ProductId is not valid (does not exists) ? I would like to display a nicer page than the default Tapestry's Exception page. The problem is that the exception occurs while parsing the ProductDetails's specification page (ProductDetails.page) where components are binded. Have you got any idea or method on how to manage that kind of problems ? thanks a lot for your experience share. Cyrille. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
-- Best regards, Renat Zubairov --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]