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