2008-03-17
FormClientPersistence
Tapestry's client persistence is great, but can be over-zealous in encoding the data to every URL in sight. Sometimes, what you want is for normal navigation links to remain unsullies, but forms to get the client persisted data so that if they cause a page re-render due to validation, everything still works. This persistence strategy does just that...
You'll need a Persistence strategy, a persistence scope, and some hivemodule magic. Once it's done, just use @Persist("client:form") to use.
The strategy:
The scope:
The hivemodule config:
转自:http://wiki.apache.org/tapestry/FormClientPersistence
You'll need a Persistence strategy, a persistence scope, and some hivemodule magic. Once it's done, just use @Persist("client:form") to use.
The strategy:
package com.zillow.web.infrastructure;
import org.apache.tapestry.engine.ServiceEncoding;
import org.apache.tapestry.record.ClientPropertyPersistenceStrategy;
public class FormClientPropertyPersistenceStrategy extends
ClientPropertyPersistenceStrategy {
@Override
public void addParametersForPersistentProperties(ServiceEncoding encoding, boolean post){
if ( post )
super.addParametersForPersistentProperties( encoding, post );
}
}
The scope:
package com.zillow.web.infrastructure;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.engine.ServiceEncoding;
import org.apache.tapestry.record.AbstractPrefixedClientPropertyPersistenceScope;
import org.apache.tapestry.record.PersistentPropertyData;
public class FormClientPropertyPersistenceScope extends
AbstractPrefixedClientPropertyPersistenceScope
{
private IRequestCycle _requestCycle;
public FormClientPropertyPersistenceScope()
{
super( "form:" );
}
public boolean shouldEncodeState(ServiceEncoding encoding, String pageName,
PersistentPropertyData data)
{
return pageName.equals(_requestCycle.getPage().getPageName());
}
public void setRequestCycle(IRequestCycle requestCycle)
{
_requestCycle = requestCycle;
}
}
The hivemodule config:
<service-point id="FormClientPropertyPersistenceScope"
interface="org.apache.tapestry.record.ClientPropertyPersistenceScope">
<invoke-factory>
<construct class="com.zillow.web.infrastructure.FormClientPropertyPersistenceScope">
<set-object property="requestCycle" value="infrastructure:requestCycle"/>
</construct>
</invoke-factory>
</service-point>
<service-point id="FormClientPropertyPersistenceStrategy"
interface="org.apache.tapestry.record.PropertyPersistenceStrategy">
<invoke-factory model="threaded">
<construct class="com.zillow.web.infrastructure.FormClientPropertyPersistenceStrategy">
<set-object property="request" value="infrastructure:request"/>
<set-object property="scope" value="service:FormClientPropertyPersistenceScope"/>
</construct>
</invoke-factory>
</service-point>
<contribution configuration-id="tapestry.persist.PersistenceStrategy">
<strategy name="client:form" object="service:FormClientPropertyPersistenceStrategy"/>
</contribution>
转自:http://wiki.apache.org/tapestry/FormClientPersistence
发表评论
- 浏览: 3365 次
- 性别:

- 来自: 深圳

- 详细资料
搜索本博客
我的相册
image031
共 53 张
共 53 张
链接
最新评论
-
自定义Hibernate Dialect ...
呵呵,对于Hibernate我也算不上很熟练,大家互相学习吧,最近都很久没弄了
-- by jackytang520 -
自定义Hibernate Dialect ...
太高兴看到了。 出这样的问题. 我们这些菜鸟 是没办法解决的. 能交 ...
-- by yyy851124 -
英文Locale下使用中文输入 ...
好文章,学习了.
-- by devin






评论排行榜