You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Paul Stanton <pa...@gunnsoft.com.au> on 2007/04/27 02:58:20 UTC

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="nextPageName@Hidden" value="ognl:forwardTo"/>
...

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




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


Sample T5 Applications

Posted by "Allen, Mark C." <Ma...@va.gov>.
I'm a newbie to Tapestry looking for any sample applications. I have
seen all the screen casts (which are cool) but I am looking for an
example that is a little more involved. Does anyone have or know of any
good T5 sample applications?  

I am looking for something that digs deeper into BeanEditForm including;
customizing the submit button and creating drop downs that are not enum
based (I would like to use an array/list).

Thanks,
 Mark

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