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:[EMAIL PROTECTED] 
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: [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