You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Cyrille37 <cy...@gmail.com> on 2006/12/03 14:08:49 UTC

information about trapping exception

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: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: information about trapping exception

Posted by Jesse Kuhnert <jk...@gmail.com>.
I believe that also gets covered on the website:

http://tapestry.apache.org/tapestry4.1/developmentguide/exceptionpages.html

On 12/3/06, Sam Gendler <sg...@ideasculptor.com> wrote:
> In hivmind.xml:
>
>     <contribution configuration-id="tapestry.InfrastructureOverrides">
>         <property name="exceptionPageName" value="CustomExceptionPage"/>
>     </contribution>
>
> In your template for the custom exception:
>
>  <span jwcid="exception"/>
>
> will render the exception if you have the following in your .page file:
>
>   <component id="exception" type="ExceptionDisplay">
>     <binding name="exceptions" value="ognl:exceptions"/>
>   </component>
>
> You can also use the following to render the request
>
>    <component id="request" type="RequestDisplay" />
>
> My class looks like this:
>
> public abstract class CustomExceptionPage extends StaticBasePage
> implements PageDetachListener {
>
>     public abstract void setExceptions(ExceptionDescription[] exceptions);
>
>     private static Logger log = Logger.getLogger(CustomExceptionPage.class);
>
>     public void setException(Throwable value)
>     {
>         log.error(value, value);
>         ExceptionAnalyzer analyzer = new ExceptionAnalyzer();
>         ExceptionDescription[] exceptions = analyzer.analyze(value);
>         setExceptions(exceptions);
>
>     }
> }
>
> I don't remember where I got all that from, but it was either Kent
> Tong's book or the user guide on the Tapestry website.  There is a
> small chance I found it in "Tapestry in Action" which is the Tap 3
> book.
>
> --sam
>
>
> On 12/3/06, Cyrille37 <cy...@gmail.com> 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: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Jesse Kuhnert
Tapestry/Dojo/(and a dash of TestNG), team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com

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


Re: information about trapping exception

Posted by Sam Gendler <sg...@ideasculptor.com>.
In hivmind.xml:

    <contribution configuration-id="tapestry.InfrastructureOverrides">
        <property name="exceptionPageName" value="CustomExceptionPage"/>
    </contribution>

In your template for the custom exception:

 <span jwcid="exception"/>

will render the exception if you have the following in your .page file:

  <component id="exception" type="ExceptionDisplay">
    <binding name="exceptions" value="ognl:exceptions"/>
  </component>

You can also use the following to render the request

   <component id="request" type="RequestDisplay" />

My class looks like this:

public abstract class CustomExceptionPage extends StaticBasePage
implements PageDetachListener {

    public abstract void setExceptions(ExceptionDescription[] exceptions);

    private static Logger log = Logger.getLogger(CustomExceptionPage.class);

    public void setException(Throwable value)
    {
        log.error(value, value);
        ExceptionAnalyzer analyzer = new ExceptionAnalyzer();
        ExceptionDescription[] exceptions = analyzer.analyze(value);
        setExceptions(exceptions);

    }
}

I don't remember where I got all that from, but it was either Kent
Tong's book or the user guide on the Tapestry website.  There is a
small chance I found it in "Tapestry in Action" which is the Tap 3
book.

--sam


On 12/3/06, Cyrille37 <cy...@gmail.com> 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: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

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


Re: information about trapping exception

Posted by Renat Zubairov <re...@gmail.com>.
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 <cy...@gmail.com> 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: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Best regards,
Renat Zubairov

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