You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Jeff Jones <jj...@trap9.com> on 2002/04/09 00:51:43 UTC

Re: setTemplate() vs doRedirect()

Hello Turbine-Users,

If a user isn't logged in, I want them to be taken to a login screen.

However, if I use setTemplate() (or data.setScreenTemplate()) in
isAuthorized() to redirect them (as suggested in the turbine documentation,
and in the newapp sample), the doBuildTemplate() method is not called in the
target page, so my context is not populated and the target login page fails.

Is this the correct behavior for setTemplate() / data.setScreenTemplate()?

If I use doRedirect instead (as listed below), it works fine - halting the
current screen and forwarding to the other.  But I'm not sure I'm supposed
to do that (for example, what is the return value of isAuthorized() used
for?)...

Any thoughts on when to use doRedirect instead of setTemplate() and why?

Jeff

PS.  Thanks for a great framework, Turbine team.

--

public class OnlineMainScreen extends VelocitySecureScreen {

    public void doBuildTemplate(RunData data, Context context) {
        System.out.println("building online,main screen");
        OnlineScreen.insertScreenTools(data,context);
    }

    protected boolean isAuthorized( RunData data )  throws Exception {
        boolean isAuthorized = false;
        if(customerAuthenticated()) {
            System.out.println("customer authenticated");
            isAuthorized = true;
        } else {
            System.out.println("customer not authenticated - sending to
online,Default.vm");
            //data.setScreenTemplate("online,Default.vm");
            //OnlineScreen.insertScreenTools(data,getContext(data));
            //setTemplate(data,"online,Default.vm");
            doRedirect(data, "online,Default.vm");
        }
        return isAuthorized;
    }
}



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>