You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Andreas Pardeike <ap...@fsys.se> on 2008/03/13 12:23:57 UTC

Login google-style (with redirect after ajax form refresh)

Hi,

I have a login component that updates itself via a zone. Works
great especially when you enter wrong values (server side verified).

Now, if the form successfully logs in or out, I want to refresh
the current page because it likely looks different because of the
state change.

I tried many things including a <script></script> inside the block
but since its an ajax request, JS is not executed. Or is it and
I am doing something wrong.

Any insides appreciated,
Andreas Pardeike

--

Here is my Login component:

<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd 
">
   <div class="kl-login-container">
     <div style="border:1px solid red">
       <t:zone t:id="loginzone" t:update="show">
         <t:delegate to="formblock" />
       </t:zone>
     </div>
   </div>
   <t:block t:id="formblock">
     <t:form t:id="loginform" class="kl-login-content"  
t:zone="loginzone">
       <t:if test="loggedIn" negate="true">
         <t:if test="isWrongLogin" negate="true">
           <p class="kl-login-head">${message:titleok}</p>
         </t:if>
         <t:if test="isWrongLogin">
           <p class="kl-login-head">${message:titlebad}</p>
         </t:if>
         <div class="kl-login-input">
           <t:textfield class="email" t:id="email"  
validate="required,regexp" />
           <t:submit class="button" value="message:login" />
         </div>
         <div class="kl-login-autologin">
           <t:checkbox t:id="autologin" />
           <span class="automessage">${message:automessage}</span>
         </div>
         <div style="clear:both" />
       </t:if>
       <t:if test="loggedIn">
         <p class="kl-login-head">${message:loggedinas} $ 
{customerDisplayName}</p>
         <div class="kl-login-input">
           <t:submit class="button" value="message:logout" />
         </div>
       </t:if>
     </t:form>
     <t:if test="refreshPage">
       Redirecting..<br />
       <script>
         alert('redirect!');
         document.location = document.location;
       </script>
     </t:if>
   </t:block>
</t:container>


and it's source:


package se.fsys.klubb.components.login;

import org.apache.tapestry.Block;
import org.apache.tapestry.annotations.ApplicationState;
import org.apache.tapestry.annotations.OnEvent;
import org.apache.tapestry.annotations.Property;
import org.apache.tapestry.ioc.annotations.Inject;

import se.fsys.klubb.access.AccessController;
import se.fsys.klubb.aso.Session;
import se.fsys.klubb.beans.Credentials;

public class Login
{
   @Inject
   private Block formblock;

   @ApplicationState
   private Session _session;
   private boolean _sessionExists;

   @Inject
   private AccessController _access;

   @Property
   private String _email;

   @Property
   private boolean _autologin;

   @SuppressWarnings("unused")
   @Property
   private boolean _isWrongLogin;

   @SuppressWarnings("unused")
   @Property
   private boolean _refreshPage;

   public Block getFormBlock()
   {
     return formblock;
   }

   @OnEvent(component = "loginform", value = "success")
   public Block successFromLoginForm()
   {
     _isWrongLogin = false;
     _refreshPage = false;

     // log out
     //
     if(isLoggedIn())
     {
       _session.setCredentials(null, true);
       _access.clearAutoCredentialsCookie();
       _refreshPage = true;
     }

     // log in
     //
     Credentials credentials = new Credentials();
     credentials.setCustomerID(_email);
     if(_access.validateCredentials(credentials))
     {
       _session.setCredentials(credentials, false);
       if(_autologin)
         _access.writeAutoCredentialsToCookie(credentials);
       _refreshPage = true;
     }
     else
     {
       if(_sessionExists)
         _session.setCredentials(null, true);
       _access.clearAutoCredentialsCookie();
       _isWrongLogin = true;
     }

     return formblock;
   }

   public boolean isLoggedIn()
   {
     if(!_sessionExists)
       return false;
     return _session.getCredentialsValid();
   }

   public String getCustomerDisplayName()
   {
     return _session.getCredentials().getCustomerDisplayName();
   }
}

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


Re: Login google-style (with redirect after ajax form refresh)

Posted by Josh Canfield <jo...@thedailytube.com>.
Executing script in an ajax response requires parsing out the script
and eval'ing it separately (your browser protecting you from scripting
attacks). This can be done with scriptaculous but is disabled by
default. I can't see a way to override this in Tapestry without
duplicating code from tapestry.js.

Tapestry is also using
http://wiki.script.aculo.us/scriptaculous/show/Ajax.Request
instead of
http://wiki.script.aculo.us/scriptaculous/show/Ajax.Updater

which, at least as documented, is the recommended object for ajax
requests that returns rendered content... (I'm not sure why it's the
recommended object, that's just what the docs say...)

You'll probably have to write some of your own javascript to get this
to work at this time...

Josh

On Thu, Mar 13, 2008 at 4:23 AM, Andreas Pardeike <ap...@fsys.se> wrote:
> Hi,
>
> I have a login component that updates itself via a zone. Works
> great especially when you enter wrong values (server side verified).
>
> Now, if the form successfully logs in or out, I want to refresh
> the current page because it likely looks different because of the
> state change.
>
> I tried many things including a <script></script> inside the block
> but since its an ajax request, JS is not executed. Or is it and
> I am doing something wrong.
>
> Any insides appreciated,
> Andreas Pardeike
>
> --
>
> Here is my Login component:
>
> <t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd
> ">
>   <div class="kl-login-container">
>     <div style="border:1px solid red">
>       <t:zone t:id="loginzone" t:update="show">
>         <t:delegate to="formblock" />
>       </t:zone>
>     </div>
>   </div>
>   <t:block t:id="formblock">
>     <t:form t:id="loginform" class="kl-login-content"
> t:zone="loginzone">
>       <t:if test="loggedIn" negate="true">
>         <t:if test="isWrongLogin" negate="true">
>           <p class="kl-login-head">${message:titleok}</p>
>         </t:if>
>         <t:if test="isWrongLogin">
>           <p class="kl-login-head">${message:titlebad}</p>
>         </t:if>
>         <div class="kl-login-input">
>           <t:textfield class="email" t:id="email"
> validate="required,regexp" />
>           <t:submit class="button" value="message:login" />
>         </div>
>         <div class="kl-login-autologin">
>           <t:checkbox t:id="autologin" />
>           <span class="automessage">${message:automessage}</span>
>         </div>
>         <div style="clear:both" />
>       </t:if>
>       <t:if test="loggedIn">
>         <p class="kl-login-head">${message:loggedinas} $
> {customerDisplayName}</p>
>         <div class="kl-login-input">
>           <t:submit class="button" value="message:logout" />
>         </div>
>       </t:if>
>     </t:form>
>     <t:if test="refreshPage">
>       Redirecting..<br />
>       <script>
>         alert('redirect!');
>         document.location = document.location;
>       </script>
>     </t:if>
>   </t:block>
> </t:container>
>
>
> and it's source:
>
>
> package se.fsys.klubb.components.login;
>
> import org.apache.tapestry.Block;
> import org.apache.tapestry.annotations.ApplicationState;
> import org.apache.tapestry.annotations.OnEvent;
> import org.apache.tapestry.annotations.Property;
> import org.apache.tapestry.ioc.annotations.Inject;
>
> import se.fsys.klubb.access.AccessController;
> import se.fsys.klubb.aso.Session;
> import se.fsys.klubb.beans.Credentials;
>
> public class Login
> {
>   @Inject
>   private Block formblock;
>
>   @ApplicationState
>   private Session _session;
>   private boolean _sessionExists;
>
>   @Inject
>   private AccessController _access;
>
>   @Property
>   private String _email;
>
>   @Property
>   private boolean _autologin;
>
>   @SuppressWarnings("unused")
>   @Property
>   private boolean _isWrongLogin;
>
>   @SuppressWarnings("unused")
>   @Property
>   private boolean _refreshPage;
>
>   public Block getFormBlock()
>   {
>     return formblock;
>   }
>
>   @OnEvent(component = "loginform", value = "success")
>   public Block successFromLoginForm()
>   {
>     _isWrongLogin = false;
>     _refreshPage = false;
>
>     // log out
>     //
>     if(isLoggedIn())
>     {
>       _session.setCredentials(null, true);
>       _access.clearAutoCredentialsCookie();
>       _refreshPage = true;
>     }
>
>     // log in
>     //
>     Credentials credentials = new Credentials();
>     credentials.setCustomerID(_email);
>     if(_access.validateCredentials(credentials))
>     {
>       _session.setCredentials(credentials, false);
>       if(_autologin)
>         _access.writeAutoCredentialsToCookie(credentials);
>       _refreshPage = true;
>     }
>     else
>     {
>       if(_sessionExists)
>         _session.setCredentials(null, true);
>       _access.clearAutoCredentialsCookie();
>       _isWrongLogin = true;
>     }
>
>     return formblock;
>   }
>
>   public boolean isLoggedIn()
>   {
>     if(!_sessionExists)
>       return false;
>     return _session.getCredentialsValid();
>   }
>
>   public String getCustomerDisplayName()
>   {
>     return _session.getCredentials().getCustomerDisplayName();
>   }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.

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


RE: Login google-style (with redirect after ajax form refresh)

Posted by Cordenier Christophe <Ch...@atosorigin.com>.
Actually,

I think that @Environment is used for RenderRequest,
but in the case of an Ajax Request, the "PartialMarkupRenderer" is used to send an answer to the client.

For example, I Think that Tapestry Zone component uses this mechanism to register form components declared inside the zone after a refresh-zone request.

But I haven't already tested the new "zone" attribute of the Form component and I don't know if it uses a similar mechanism.

Christophe.

-----Message d'origine-----
De : Andreas Pardeike [mailto:ap@fsys.se]
Envoyé : jeudi 13 mars 2008 13:34
À : Tapestry users
Objet : Re: Login google-style (with redirect after ajax form refresh)

PS:

I use Tapestry 5.0.12-SNAPSHOT...

/Andreas

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




Ce message et les pièces jointes sont confidentiels et réservés à l'usage exclusif de ses destinataires. Il peut également être protégé par le secret professionnel. Si vous recevez ce message par erreur, merci d'en avertir immédiatement l'expéditeur et de le détruire. L'intégrité du message ne pouvant être assurée sur Internet, la responsabilité du groupe Atos Origin ne pourra être recherchée quant au contenu de ce message. Bien que les meilleurs efforts soient faits pour maintenir cette transmission exempte de tout virus, l'expéditeur ne donne aucune garantie à cet égard et sa responsabilité ne saurait être recherchée pour tout dommage résultant d'un virus transmis.

This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Atos Origin group liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted.


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


Re: Login google-style (with redirect after ajax form refresh)

Posted by Andreas Pardeike <ap...@fsys.se>.
PS:

I use Tapestry 5.0.12-SNAPSHOT...

/Andreas

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


Re: Login google-style (with redirect after ajax form refresh)

Posted by Andreas Pardeike <ap...@fsys.se>.
Actually, I get a

[ERROR] ExceptionHandler  
org.apache.tapestry.runtime.ComponentEventException: No object of type  
org.apache.tapestry.PageRenderSupport is available from the  
Environment.  Available types are  
org.apache.tapestry.ValidationTracker,  
org.apache.tapestry.services.ComponentEventResultProcessor,  
org.apache.tapestry.services.FormSupport,  
org.apache.tapestry.services.Heartbeat. [at classpath:se/fsys/klubb/ 
components/login/Login.tml, line 10, column 72]

when I change

> if(isLoggedIn())
> {
>   _session.setCredentials(null, true);
>   _access.clearAutoCredentialsCookie();
>   _refreshPage = true;
> }


to

@Environmental
private PageRenderSupport _pageRenderSupport;
...
if(isLoggedIn())
{
   _session.setCredentials(null, true);
   _access.clearAutoCredentialsCookie();
   _pageRenderSupport.addScript("alert('redirect');'");
}

I really would love to see an improvement on

> @OnEvent(component = "loginform", value = "success")

> public Object successFromLoginForm()

so the type of action is determined by the object type I return. It  
would follow the style of a normal listener so I could return a string  
to redirect, a page instance to go to that page, a Block to render the  
ajax response or (and that is my favorite) 'null' to just refresh the  
zone so I don't have to hack around this as in the example below.

Howard?

/Andreas Pardeike


On 13 mar 2008, at 13.13, Cordenier Christophe wrote:

> Hello,
>
> To add Javascript after an action on the server side, you can use  
> the PageRenderSupport class.
>
> Actually, this may work for Ajax and non-Ajax request.
>
> To inject this class in your component :
>
>    @Environmental
>    private PageRenderSupport _pageRenderSupport;
>
> Hope it helps.
>
> Christophe.
>
> -----Message d'origine-----
> De : Andreas Pardeike [mailto:ap@fsys.se]
> Envoyé : jeudi 13 mars 2008 12:24
> À : Tapestry users
> Objet : Login google-style (with redirect after ajax form refresh)
>
> I have a login component that updates itself via a zone. Works
> great especially when you enter wrong values (server side verified).
>
> Now, if the form successfully logs in or out, I want to refresh
> the current page because it likely looks different because of the
> state change.
>
> I tried many things including a <script></script> inside the block
> but since its an ajax request, JS is not executed. Or is it and
> I am doing something wrong.
>
> Any insides appreciated,
> Andreas Pardeike
>
> --
>
> Here is my Login component:
>
> <t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd
> ">
>   <div class="kl-login-container">
>     <div style="border:1px solid red">
>       <t:zone t:id="loginzone" t:update="show">
>         <t:delegate to="formblock" />
>       </t:zone>
>     </div>
>   </div>
>   <t:block t:id="formblock">
>     <t:form t:id="loginform" class="kl-login-content"
> t:zone="loginzone">
>       <t:if test="loggedIn" negate="true">
>         <t:if test="isWrongLogin" negate="true">
>           <p class="kl-login-head">${message:titleok}</p>
>         </t:if>
>         <t:if test="isWrongLogin">
>           <p class="kl-login-head">${message:titlebad}</p>
>         </t:if>
>         <div class="kl-login-input">
>           <t:textfield class="email" t:id="email"
> validate="required,regexp" />
>           <t:submit class="button" value="message:login" />
>         </div>
>         <div class="kl-login-autologin">
>           <t:checkbox t:id="autologin" />
>           <span class="automessage">${message:automessage}</span>
>         </div>
>         <div style="clear:both" />
>       </t:if>
>       <t:if test="loggedIn">
>         <p class="kl-login-head">${message:loggedinas} $
> {customerDisplayName}</p>
>         <div class="kl-login-input">
>           <t:submit class="button" value="message:logout" />
>         </div>
>       </t:if>
>     </t:form>
>     <t:if test="refreshPage">
>       Redirecting..<br />
>       <script>
>         alert('redirect!');
>         document.location = document.location;
>       </script>
>     </t:if>
>   </t:block>
> </t:container>
>
>
> and it's source:
>
>
> package se.fsys.klubb.components.login;
>
> import org.apache.tapestry.Block;
> import org.apache.tapestry.annotations.ApplicationState;
> import org.apache.tapestry.annotations.OnEvent;
> import org.apache.tapestry.annotations.Property;
> import org.apache.tapestry.ioc.annotations.Inject;
>
> import se.fsys.klubb.access.AccessController;
> import se.fsys.klubb.aso.Session;
> import se.fsys.klubb.beans.Credentials;
>
> public class Login
> {
>   @Inject
>   private Block formblock;
>
>   @ApplicationState
>   private Session _session;
>   private boolean _sessionExists;
>
>   @Inject
>   private AccessController _access;
>
>   @Property
>   private String _email;
>
>   @Property
>   private boolean _autologin;
>
>   @SuppressWarnings("unused")
>   @Property
>   private boolean _isWrongLogin;
>
>   @SuppressWarnings("unused")
>   @Property
>   private boolean _refreshPage;
>
>   public Block getFormBlock()
>   {
>     return formblock;
>   }
>
>   @OnEvent(component = "loginform", value = "success")
>   public Block successFromLoginForm()
>   {
>     _isWrongLogin = false;
>     _refreshPage = false;
>
>     // log out
>     //
>     if(isLoggedIn())
>     {
>       _session.setCredentials(null, true);
>       _access.clearAutoCredentialsCookie();
>       _refreshPage = true;
>     }
>
>     // log in
>     //
>     Credentials credentials = new Credentials();
>     credentials.setCustomerID(_email);
>     if(_access.validateCredentials(credentials))
>     {
>       _session.setCredentials(credentials, false);
>       if(_autologin)
>         _access.writeAutoCredentialsToCookie(credentials);
>       _refreshPage = true;
>     }
>     else
>     {
>       if(_sessionExists)
>         _session.setCredentials(null, true);
>       _access.clearAutoCredentialsCookie();
>       _isWrongLogin = true;
>     }
>
>     return formblock;
>   }
>
>   public boolean isLoggedIn()
>   {
>     if(!_sessionExists)
>       return false;
>     return _session.getCredentialsValid();
>   }
>
>   public String getCustomerDisplayName()
>   {
>     return _session.getCredentials().getCustomerDisplayName();
>   }
> }

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


RE: Login google-style (with redirect after ajax form refresh)

Posted by Cordenier Christophe <Ch...@atosorigin.com>.
Hello,

To add Javascript after an action on the server side, you can use the PageRenderSupport class.

Actually, this may work for Ajax and non-Ajax request.

To inject this class in your component :

    @Environmental
    private PageRenderSupport _pageRenderSupport;

Hope it helps.


Christophe.


-----Message d'origine-----
De : Andreas Pardeike [mailto:ap@fsys.se]
Envoyé : jeudi 13 mars 2008 12:24
À : Tapestry users
Objet : Login google-style (with redirect after ajax form refresh)

Hi,

I have a login component that updates itself via a zone. Works
great especially when you enter wrong values (server side verified).

Now, if the form successfully logs in or out, I want to refresh
the current page because it likely looks different because of the
state change.

I tried many things including a <script></script> inside the block
but since its an ajax request, JS is not executed. Or is it and
I am doing something wrong.

Any insides appreciated,
Andreas Pardeike

--

Here is my Login component:

<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd
">
   <div class="kl-login-container">
     <div style="border:1px solid red">
       <t:zone t:id="loginzone" t:update="show">
         <t:delegate to="formblock" />
       </t:zone>
     </div>
   </div>
   <t:block t:id="formblock">
     <t:form t:id="loginform" class="kl-login-content"
t:zone="loginzone">
       <t:if test="loggedIn" negate="true">
         <t:if test="isWrongLogin" negate="true">
           <p class="kl-login-head">${message:titleok}</p>
         </t:if>
         <t:if test="isWrongLogin">
           <p class="kl-login-head">${message:titlebad}</p>
         </t:if>
         <div class="kl-login-input">
           <t:textfield class="email" t:id="email"
validate="required,regexp" />
           <t:submit class="button" value="message:login" />
         </div>
         <div class="kl-login-autologin">
           <t:checkbox t:id="autologin" />
           <span class="automessage">${message:automessage}</span>
         </div>
         <div style="clear:both" />
       </t:if>
       <t:if test="loggedIn">
         <p class="kl-login-head">${message:loggedinas} $
{customerDisplayName}</p>
         <div class="kl-login-input">
           <t:submit class="button" value="message:logout" />
         </div>
       </t:if>
     </t:form>
     <t:if test="refreshPage">
       Redirecting..<br />
       <script>
         alert('redirect!');
         document.location = document.location;
       </script>
     </t:if>
   </t:block>
</t:container>


and it's source:


package se.fsys.klubb.components.login;

import org.apache.tapestry.Block;
import org.apache.tapestry.annotations.ApplicationState;
import org.apache.tapestry.annotations.OnEvent;
import org.apache.tapestry.annotations.Property;
import org.apache.tapestry.ioc.annotations.Inject;

import se.fsys.klubb.access.AccessController;
import se.fsys.klubb.aso.Session;
import se.fsys.klubb.beans.Credentials;

public class Login
{
   @Inject
   private Block formblock;

   @ApplicationState
   private Session _session;
   private boolean _sessionExists;

   @Inject
   private AccessController _access;

   @Property
   private String _email;

   @Property
   private boolean _autologin;

   @SuppressWarnings("unused")
   @Property
   private boolean _isWrongLogin;

   @SuppressWarnings("unused")
   @Property
   private boolean _refreshPage;

   public Block getFormBlock()
   {
     return formblock;
   }

   @OnEvent(component = "loginform", value = "success")
   public Block successFromLoginForm()
   {
     _isWrongLogin = false;
     _refreshPage = false;

     // log out
     //
     if(isLoggedIn())
     {
       _session.setCredentials(null, true);
       _access.clearAutoCredentialsCookie();
       _refreshPage = true;
     }

     // log in
     //
     Credentials credentials = new Credentials();
     credentials.setCustomerID(_email);
     if(_access.validateCredentials(credentials))
     {
       _session.setCredentials(credentials, false);
       if(_autologin)
         _access.writeAutoCredentialsToCookie(credentials);
       _refreshPage = true;
     }
     else
     {
       if(_sessionExists)
         _session.setCredentials(null, true);
       _access.clearAutoCredentialsCookie();
       _isWrongLogin = true;
     }

     return formblock;
   }

   public boolean isLoggedIn()
   {
     if(!_sessionExists)
       return false;
     return _session.getCredentialsValid();
   }

   public String getCustomerDisplayName()
   {
     return _session.getCredentials().getCustomerDisplayName();
   }
}

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




Ce message et les pièces jointes sont confidentiels et réservés à l'usage exclusif de ses destinataires. Il peut également être protégé par le secret professionnel. Si vous recevez ce message par erreur, merci d'en avertir immédiatement l'expéditeur et de le détruire. L'intégrité du message ne pouvant être assurée sur Internet, la responsabilité du groupe Atos Origin ne pourra être recherchée quant au contenu de ce message. Bien que les meilleurs efforts soient faits pour maintenir cette transmission exempte de tout virus, l'expéditeur ne donne aucune garantie à cet égard et sa responsabilité ne saurait être recherchée pour tout dommage résultant d'un virus transmis.

This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Atos Origin group liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted.


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


AW: Login google-style (with redirect after ajax form refresh)

Posted by "Stroeber, Andreas" <an...@siemens.com>.
I'm not sure about T5 (haven't even touched it yet) but in T4 I use a simple redirect answer. PageRedirectException should do, too. Works also with AJAX-Requests. The only thing in T4 is, that you are not able to inject parameters into the redirected page when using AJAX-requests (you have to pass them via session). 

    public IPage onDoLogin(IRequestCycle cycle) {
        User u = null;

        try {
            u = AuthenticationService.authenticate(getUsername(), getPassword());
            return cycle.getPage("Start");

        } catch (AuthenticationException ex) {
            setInfoMessage("Foo");
            return null;

        }
	}

Hope this helps.
Grz
Andi


-----Ursprüngliche Nachricht-----
Von: Andreas Pardeike [mailto:ap@fsys.se] 
Gesendet: Donnerstag, 13. März 2008 12:24
An: Tapestry users
Betreff: Login google-style (with redirect after ajax form refresh)

Hi,

I have a login component that updates itself via a zone. Works great especially when you enter wrong values (server side verified).

Now, if the form successfully logs in or out, I want to refresh the current page because it likely looks different because of the state change.

I tried many things including a <script></script> inside the block but since its an ajax request, JS is not executed. Or is it and I am doing something wrong.

Any insides appreciated,
Andreas Pardeike

--

Here is my Login component:

<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd
">
   <div class="kl-login-container">
     <div style="border:1px solid red">
       <t:zone t:id="loginzone" t:update="show">
         <t:delegate to="formblock" />
       </t:zone>
     </div>
   </div>
   <t:block t:id="formblock">
     <t:form t:id="loginform" class="kl-login-content"  
t:zone="loginzone">
       <t:if test="loggedIn" negate="true">
         <t:if test="isWrongLogin" negate="true">
           <p class="kl-login-head">${message:titleok}</p>
         </t:if>
         <t:if test="isWrongLogin">
           <p class="kl-login-head">${message:titlebad}</p>
         </t:if>
         <div class="kl-login-input">
           <t:textfield class="email" t:id="email"  
validate="required,regexp" />
           <t:submit class="button" value="message:login" />
         </div>
         <div class="kl-login-autologin">
           <t:checkbox t:id="autologin" />
           <span class="automessage">${message:automessage}</span>
         </div>
         <div style="clear:both" />
       </t:if>
       <t:if test="loggedIn">
         <p class="kl-login-head">${message:loggedinas} $ {customerDisplayName}</p>
         <div class="kl-login-input">
           <t:submit class="button" value="message:logout" />
         </div>
       </t:if>
     </t:form>
     <t:if test="refreshPage">
       Redirecting..<br />
       <script>
         alert('redirect!');
         document.location = document.location;
       </script>
     </t:if>
   </t:block>
</t:container>


and it's source:


package se.fsys.klubb.components.login;

import org.apache.tapestry.Block;
import org.apache.tapestry.annotations.ApplicationState;
import org.apache.tapestry.annotations.OnEvent;
import org.apache.tapestry.annotations.Property;
import org.apache.tapestry.ioc.annotations.Inject;

import se.fsys.klubb.access.AccessController;
import se.fsys.klubb.aso.Session;
import se.fsys.klubb.beans.Credentials;

public class Login
{
   @Inject
   private Block formblock;

   @ApplicationState
   private Session _session;
   private boolean _sessionExists;

   @Inject
   private AccessController _access;

   @Property
   private String _email;

   @Property
   private boolean _autologin;

   @SuppressWarnings("unused")
   @Property
   private boolean _isWrongLogin;

   @SuppressWarnings("unused")
   @Property
   private boolean _refreshPage;

   public Block getFormBlock()
   {
     return formblock;
   }

   @OnEvent(component = "loginform", value = "success")
   public Block successFromLoginForm()
   {
     _isWrongLogin = false;
     _refreshPage = false;

     // log out
     //
     if(isLoggedIn())
     {
       _session.setCredentials(null, true);
       _access.clearAutoCredentialsCookie();
       _refreshPage = true;
     }

     // log in
     //
     Credentials credentials = new Credentials();
     credentials.setCustomerID(_email);
     if(_access.validateCredentials(credentials))
     {
       _session.setCredentials(credentials, false);
       if(_autologin)
         _access.writeAutoCredentialsToCookie(credentials);
       _refreshPage = true;
     }
     else
     {
       if(_sessionExists)
         _session.setCredentials(null, true);
       _access.clearAutoCredentialsCookie();
       _isWrongLogin = true;
     }

     return formblock;
   }

   public boolean isLoggedIn()
   {
     if(!_sessionExists)
       return false;
     return _session.getCredentialsValid();
   }

   public String getCustomerDisplayName()
   {
     return _session.getCredentials().getCustomerDisplayName();
   }
}

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


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