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:[EMAIL PROTECTED]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to