You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Geoffrey Wiseman <ge...@gmail.com> on 2009/03/11 21:42:43 UTC

Index Pages, 404s and Redirects

I'd like to use an Index page at the root of my Tapestry application (mostly
to get the / URL in links rather than /start), but I'd like to respond to
some of those page requests with a 404.
I've done this using the pattern described on the last a few times by adding
an onActivate(EventContext), which I look at to decide if I want to return
an instance of a PageNotFound page.  This results in a redirect, which I
believe is because this is an event handling-method.  I like the
redirect-after-post pattern, and most of the time, I'd probably like to keep
that as a default.  For this particular page, I don't want to use a redirect
-- in part because I want the original request to 404, in keeping with the
resource-oriented view of HTML.  Also, if I make a request for /myNewPage
before it's there, and I then implement it and refresh, I want the resulting
request to be for /myNewPage not /pagenotfound, which it'll be after the
redirect.

So is it possible to avoid the redirect here without disabling
redirect-after-post for the rest of Tapestry.

To be honest, if I could use a start page and get a "/" link instead of
"/start" that would also solve my problem for the time being -- although I
like the ability to provide a custom 404 tapestry page that this will give
me.

  - Geoffrey
-- 
Geoffrey Wiseman
http://www.geoffreywiseman.ca/

Re: Index Pages, 404s and Redirects

Posted by Luther Baker <lu...@gmail.com>.
Is there anyway you can leverage web.xml error handling for this?


<web-app>
...
    <error-page>
        <error-code>404</error-code>
        <location>errors/FourOhFour.tml</location>
    </error-page>
    <error-page>
        <exception-type>java.lang.Throwable</exception-type>
        <location>errors/throwable.tml</location>
    </error-page>
...
</web-app>


IE: catch *specific *exceptions (what is thrown for missing pages, etc) and
push them to a Tapestry page that implements the logic you want? Please
don't take the example literally :) i.e. handle whatever exceptions and
forward to whatever pages would make sense.

-Luther



On Thu, Mar 12, 2009 at 3:28 PM, Geoffrey Wiseman <
geoffrey.wiseman@gmail.com> wrote:

> On Wed, Mar 11, 2009 at 7:33 PM, nillehammer
> <ta...@winfonet.eu> wrote:
>
> > Tapestry's Delegate-Component
> > (
> >
> http://tapestry.apache.org/tapestry5/tapestry-core/ref/org/apache/tapestry5/corelib/components/Delegate.html
> > )
> > to show an error message.
> >
>
> I guess I'm still processing this -- how would a delegate component be of
> help to me here?
> It's a little awkward to have each index template have a top-level
> conditional:
> - if this is a 'not found' then show an error
> - else show the actual page template
>
> I dunno how often I'd be repeating this pattern - perhaps very rarely.  If
> it came up more than a couple times, I'd probably live with the
> /pagenotfound approach just to avoid the duplication.  I suppose I could
> even use a layout to get around the duplication.  Anyway -- ultimately, I
> think I'm probably fighting against the grain a little too hard and should
> probably just live with the /start URL and accept that Tapestry owns the
> URL
> structure more than I'd necessarily choose.  ;)
>
>  - Geoffrey
> --
> Geoffrey Wiseman
> http://www.geoffreywiseman.ca/
>

Re: Index Pages, 404s and Redirects

Posted by Geoffrey Wiseman <ge...@gmail.com>.
On Wed, Mar 11, 2009 at 7:33 PM, nillehammer
<ta...@winfonet.eu> wrote:

> Tapestry's Delegate-Component
> (
> http://tapestry.apache.org/tapestry5/tapestry-core/ref/org/apache/tapestry5/corelib/components/Delegate.html
> )
> to show an error message.
>

I guess I'm still processing this -- how would a delegate component be of
help to me here?
It's a little awkward to have each index template have a top-level
conditional:
- if this is a 'not found' then show an error
- else show the actual page template

I dunno how often I'd be repeating this pattern - perhaps very rarely.  If
it came up more than a couple times, I'd probably live with the
/pagenotfound approach just to avoid the duplication.  I suppose I could
even use a layout to get around the duplication.  Anyway -- ultimately, I
think I'm probably fighting against the grain a little too hard and should
probably just live with the /start URL and accept that Tapestry owns the URL
structure more than I'd necessarily choose.  ;)

  - Geoffrey
-- 
Geoffrey Wiseman
http://www.geoffreywiseman.ca/

Re: Index Pages, 404s and Redirects

Posted by nillehammer <ta...@winfonet.eu>.
Hi Geoffrey,

afaik that can only be avoided by the page itsself handling the request.
So you would have to set the 404-code in onActivate
(HttpServletResponse.setStatus) and probably would want to use
Tapestry's Delegate-Component
(http://tapestry.apache.org/tapestry5/tapestry-core/ref/org/apache/tapestry5/corelib/components/Delegate.html)
to show an error message.

Regards, nillehammer

Geoffrey Wiseman schrieb:
> I'd like to use an Index page at the root of my Tapestry application (mostly
> to get the / URL in links rather than /start), but I'd like to respond to
> some of those page requests with a 404.
> I've done this using the pattern described on the last a few times by adding
> an onActivate(EventContext), which I look at to decide if I want to return
> an instance of a PageNotFound page.  This results in a redirect, which I
> believe is because this is an event handling-method.  I like the
> redirect-after-post pattern, and most of the time, I'd probably like to keep
> that as a default.  For this particular page, I don't want to use a redirect
> -- in part because I want the original request to 404, in keeping with the
> resource-oriented view of HTML.  Also, if I make a request for /myNewPage
> before it's there, and I then implement it and refresh, I want the resulting
> request to be for /myNewPage not /pagenotfound, which it'll be after the
> redirect.
> 
> So is it possible to avoid the redirect here without disabling
> redirect-after-post for the rest of Tapestry.
> 
> To be honest, if I could use a start page and get a "/" link instead of
> "/start" that would also solve my problem for the time being -- although I
> like the ability to provide a custom 404 tapestry page that this will give
> me.
> 
>   - Geoffrey

-- 
http://www.winfonet.eu

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