Hi,
The pattern suggested by Bernard felt like something I wanted to implement,
so I decided to give it a shot using friendly URL:s. But, as far as I can
tell, with Tapestry 4.0, RedirectException doesn't quite do the trick unless
you have an absolute URL. I got sent to the right page, but hitting F5 means
that the browser tries to send another POST request, indicating that no
redirect response was sent when I used the following method:
-------------
public void doSubmit() {
getEntityLister().add(getEntity()); // from a 'create new'
page, so this stores the new entity
RedirectException e = new RedirectException("ListAll.page");
e.printStackTrace(); // just to see where in the Tapestry
framework I was...
throw e;
}
-------------
I traced it down to this method in ServletWebRequest:
-------------
public void forward(String URL)
{
if (HiveMind.isBlank(URL))
{
performForward("/");
return;
}
boolean internal = !(URL.startsWith("/") || URL.indexOf("://") > 0);
if (internal)
performForward("/" + URL);
else
sendRedirect(URL);
}
-------------
So if you specify an absolute URL, Tapestry's behaviour when throwing a
RedirectException changes, so the following method appears to work:
-------------
public void doSubmit(IRequestCycle cycle) {
getEntityLister().add(getEntity());
throw new
RedirectException(cycle.getAbsoluteURL("ListAll.page"));
}
-------------
Much easier than implementing a RedirectException of your own, but perhaps a
little bit non-obvious that the semantics of throwing a RedirectException
depends on the URL. Hence this post, if someone else wants to do something
similar.
/ Petter
> Geoff Callender wrote:
> > And if you spot any poor Tapestry practises in the code
> then please let
> > me know ASAP! I'd hate to be responsible for spreading bad
> techniques.
>
> I would suggest adding redirect-after-POST pattern
>
<http://www.theserverside.com/tt/articles/article.tss?l=RedirectAfterPost>,
> to circumvent subsequent form submissions.
>
> It is especially desirable for the login screen form , because at
> present it is unsafe. (please check the following sequence: login ->
> logout -> back button -> refresh : voilla! your account was stolen)
>
> As far as tapestry 3.x is concerned PageRedirectException
> DOES NOT make
> a trick, use RedirectException or a convenient wrapper like
> TapestryRedirectException (code below, someone posted it here
> long time
> ago).
>
> Regards,
> Bernard
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]