hi paul,

i think that there is a workflow for this in here:
http://www.agileskills2.org/EWDT/

ICallback interface or something.

kind regards,
peter 

-----Ursprüngliche Nachricht-----
Von: Paul Stanton [mailto:[EMAIL PROTECTED] 
Gesendet: Freitag, 27. April 2007 02:58
An: Tapestry users
Betreff: continue from same point after log in

Hi All,

I've just got something to work which is pretty fundamental to my app, 
but I've had to hack a little to get it working. I'd appreciate 
feedback/opinions on tidier alternatives if there are any.

Basically, a user can browse the whole application except for small 
segments without logging in. When they hit a page that requires a valid 
session, they are redirected to the login page. Once they have logged in 
they should be returned to the page they were trying to access. It is 
acceptable for this to only work for GET requests, however service 
parameters (query string) must be retained.

Here's how I've achieved it:

TapestryUtils:
public class TapestryUtils
{
    public static HttpServletRequest getRequest(WebRequest request)
    {
        RequestRetriever d = new RequestRetriever();
        request.describeTo(d);
        return d.getRequest();
    }

    static class RequestRetriever implements DescriptionReceiver
    {
        HttpServletRequest request;

        public void describeAlternate(Object alternate)
        {
            this.request = (HttpServletRequest) alternate;
        }

        public HttpServletRequest getRequest()
        {
            return request;
        }
        ...
    }
}

BasePage:
public abstract class AppPage extends BasePage
{
    ....

    public void pageValidate(PageEvent event)
    {
        if (Boolean.parseBoolean(getSecure()) && !getVisit().isAuthentic())
        {
            Login page = getLoginPage();
            HttpServletRequest request = 
TapestryUtils.getRequest(getRequestCycle().getInfrastructure().getRequest());
            if (request.getMethod().equals("GET"))
                page.setForwardTo(request.getRequestURL() + "?" + 
request.getQueryString());
            throw new PageRedirectException(page);
        }
    }
}

Login
public abstract class Login extends ApplicationPage
{
    ...

    public abstract String getForwardTo();
    public abstract void setForwardTo(String forwardTo);

    public IPage doSubmit()
    {
        User user = getUserService().getUserByUsername(getUsername());

        if (user != null && user.getPassword().equals(getPassword()))
        {
            getVisit().setUser(user);
            if (getForwardTo() == null)
            {
                Home page = getHomePage();
                page.setMessage(user.getFullName() + " successfully 
logged in.");
                return page;
            }

            throw new RedirectException(getForwardTo());
        }

        setError("Invalid login. Please try again.");
        return this;
    }
}

Login.html:
...
<input type="hidden" jwcid="[EMAIL PROTECTED]" value="ognl:forwardTo"/>
...

-- 
Paul Stanton
Gunn Software
PH: (02) 9918 3666 (ext 503)




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to