Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jakarta-tapestry Wiki" 
for change notification.

The following page has been changed by JeffLubetkin:
http://wiki.apache.org/jakarta-tapestry/FormClientPersistence

New page:
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:
{{{
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>
}}}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to