You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Peter Hulst <ph...@triporama.com> on 2005/03/15 04:25:04 UTC
how to catch a fileupload exception (or use multiple exception
pages)
I'm trying to implement multiple exception pages in my application but
running into problems with that.
How can I redirect to another exception page from my custom Exception page,
or how can I send one particular type of exception to a different page?
Basically, I've created my own Exception page which works fine. In the
pageBeginRender method I create an error message and email that off to the
administrator. This works for most errors but there's one particular error
that I'd like to handle in a different way: the fileupload
SizeLimitExceededException. In that case I would like to display a
different page, instructing the user to try again with a smaller file size,
and provide a link back to the upload page.
So I check for that particular exception in my exception page and if it
occurred, I call:
throw new PageRedirectException("UploadFileTooBigError");
However, that doesn't work. It throws the following servlet exception:
javax.servlet.ServletException: UploadImageError
org.apache.tapestry.engine.AbstractEngine.activateExceptionPage(AbstractEngine.java:480)
org.apache.tapestry.engine.AbstractEngine.service(AbstractEngine.java:914)
...root cause
org.apache.tapestry.PageRedirectException: UploadImageError
triporama.webapp.pages.error.Exception.pageBeginRender(Exception.java:164)
org.apache.tapestry.AbstractPage.firePageBeginRender(AbstractPage.java:463)
org.apache.tapestry.AbstractPage.renderPage(AbstractPage.java:293)
telling me that in an Exception page it's not ok to throw a
PageRedirectException.
What else can I do to catch this
org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException
exception?
afaik there's nothing I can do in my page to catch this because this kind
of error occurs before my upload page even starts to render.
My .application file contains the following:
<extension name="org.apache.tapestry.multipart-decoder"
class="org.apache.tapestry.multipart.DefaultMultipartDecoder">
<configure property-name="maxSize" type="double" value="300000"/>
</extension>
I suppose I could simply put a big conditional in the Exception page
template and have it display different html and messages based on the type
of Exception that occurred - but there might be a better approach?
any help appreciated,
Peter
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: how to catch a fileupload exception (or use multiple exception pages)
Posted by Kent Tong <ke...@cpttm.org.mo>.
Peter Hulst <phulst <at> triporama.com> writes:
> I suppose I could simply put a big conditional in the Exception page
> template and have it display different html and messages based on the type
> of Exception that occurred - but there might be a better approach?
That's about the best way that I can think of. You could
use a Delegator in your Exception page like:
<span jwcid="@Delegator" delegate="delegate"/>
Then define getDelegate() like:
public IRenderer getDelegate() {
if (getException() instance of XXX) {
return getRequestCycle().getPage("XXXPage");
}
if (getException() instance of YYY) {
return getRequestCycle().getPage("YYYPage");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org