> Is there a way to catch the exception when the String gets gets turned > into a long so I can do something other than showing the user an > exception page? Alternatively is there a way to over-ride onActivate > so I can do something like:
I've used a link transformer to solve a similar problem. It provides a clean separation from your renaming so your code can just work as usual. If you detect that the incoming URL has the right pattern you transform it to your new pattern. Another option is to use the EventContext and test the number of context parameters. void onActivate(EventContext ctx) { if ( ctx.getCount() == 2 ) { person = ctx.get(Person.class, 0); page = ctx.get(Integer.class, 1); } else if ( ctx.getCount() == 1 ) { String first_last = ctx.get(String.class, 0); String[] parts = first_last.split('_'); person = dao.findByFirstLast(parts[0], parts[1]); page = 0; // ? } } And third, you can implement onException(Throwable t) described here: http://tapestry.formos.com/nightly/tapestry5/guide/event.html Object onException(Throwable cause) { message = cause.getMessage(); return this; } Josh On Mon, Jun 6, 2011 at 6:36 PM, Mark <mark-li...@xeric.net> wrote: > I have an app that previously displayed a list of information at a URL > like this: > /author/first_last > > Now I am switching it to use an ID: > > /author/25/1 > > Where 25 is the person id and 1 is the page of the list to display. > > I'm using something like: > > Object onActivate(Person person, int page) { > > } > > When people hit the old URL with something like: > /author/john_smith > > It throws an exception. I would prefer it show a 404 or even maybe do > a lookup and redirect them. > > Is there a way to catch the exception when the String gets gets turned > into a long so I can do something other than showing the user an > exception page? Alternatively is there a way to over-ride onActivate > so I can do something like: > > public Object onActivate(String str) { > if(person == null) { > return new HttpError(404, "Resource Not Found"); > } > return null; > } > > Or is there another solution that I'm overlooking. > > --Mark > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org