表单的重复提交

地址:http://howardlewisship.com/tapestry-javaforge/tapestry-flash/

Description

This library is an extension to Tapestry 4.0 that provides a new type of property persistence strategy, "flash". A flashed property is stored in the session only briefly ... until the next request that accesses that page.

Flashed properties are most often used to store temporary messages. They are extremely useful when combined with the redirect-after-post pattern for handling form submissions.

The name and the idea have been borrowed from Ruby On Rails.

Usage

Any property of a page or component may be marked as persisting in the flash. Using the @Persist annotation:

public abstract class MyPage extends BasePage
{
  @Persist("flash")
  public abstract String getMessage();
  
  public abstract void setMessage(String message);
  

Alternately, you may use the <property> element in a page or component specification:

<property name="message" persist="flash"/>

Flashed properties make the most sense when combined with the redirect-after-post pattern (otherwise, the flashed properties may appear to live too long: once for the initial render, then once more on the next access to the page). The redirect-after-post approach is very easy to implement in Tapestry 4.0. From the form's submit listener method:

  @InjectObject("engine-service:page")
  public abstract IEngineService getPageService();
  
  public ILink doFormSubmit()
  {
    // ... write data to a database
    
    setMessage("Your changes have been saved.");
    
    return getPageService().getLink(false, getPageName());
  }   
  

Returning an ILink from a listener method causes Tapestry to send a redirect reponse to the client web browser; the use of the page engine service will cause the current page to be redisplayed, with the message set in the listener method ("Your changes ...").

If the user refreshes the page, the form will not be resubmitted, instead, the page will simply be re-rendered. The message will, however, not appear (that is the nature of the flash; values stick around only until used the first time).

Availability

Version 1.0.0 is now available. If you don't care for Maven, you may access the binary and source distribution files at http://howardlewisship.com/downloads/tapestry-javaforge/.

你可能感兴趣的:(maven,Flash,Ruby,tapestry,Rails)