Agile
-
Tapestry4.0中的session
2006-05-11
Tapestry4之前在Page类中访问HttpSession或HttpRequest是很方便的,这样子就可以了IRequestCycle.getRequestContext().getSession(),昨天看了一下它的源代码,竟然有这样子的注释“
/**
* Returns the {@link RequestContext}. This is provided to ease the upgrade from Tapestry 3.0.
*
* @deprecated To be removed in 4.1.
*/”
在4.1的时候会被删除,虽然我现在用得还是4.0,考虑到以后的升级还是决定不这样做了。
那只好这样子用了
/**注入Request*/
@InjectObject("infrastructure:request")
public abstract WebRequest getRequest();public void login(IRequestCycle cycle) {
this.getRequest().getSession(true).setAttribute("user", getName());
}上面的方法能够在session中保存对象,可想删除怎么办呢? this.getRequest().getSession(true)这样子得到的对象是Tapestry包装的WebSession,当中竟然没有removeAttribute这个方法,郁闷。看看Api中是怎么说的,attribute the new value for the attribute, or null to delete the attribute entirely.
找到答案了,把属性设为null就从session中删除这个对象了。
this.getRequest().getSession(true).setAttribute("user", null);
用了一段时间Tapestry觉得在开发的时候最好看看它的源代码,有些问题文档上没有,看源代码就很明白了。
最近在做新的项目,竟然把以前一想就头大的javascript用了不少,第一次发现原来javascript可以这样写,在写之前看了些Prototype的东西,在写我们自己的项目的一些页面功能时,参照着Prototype的方法来做,竟然也有点面向对象编程的感觉。
刚过完五一,工作起来状态恢复得慢,今天才差不多有些感觉了,继续努力工作,好好学习:)







