View Javadoc

1   package net.sf.tacos.mixins;
2   
3   import org.apache.tapestry.ComponentResources;
4   import org.apache.tapestry.MarkupWriter;
5   import org.apache.tapestry.PageRenderSupport;
6   import org.apache.tapestry.TapestryConstants;
7   import org.apache.tapestry.annotations.Environmental;
8   import org.apache.tapestry.annotations.IncludeJavaScriptLibrary;
9   import org.apache.tapestry.annotations.Parameter;
10  import org.apache.tapestry.ioc.Messages;
11  import org.apache.tapestry.ioc.annotations.Inject;
12  
13  /**
14   * A mixin for a text field that allows you to type a date into a text field in one of the following forms: 
15   * <pre>
16   * today         tomorrow     July 2008 
17   * next friday   last April   +5years  
18   * </pre>
19   * This mixin is based on <a href="http://code.google.com/p/datejs/">datejs</a> library.
20   * 
21   * @author Igor Drobiazko
22   *
23   */
24  @IncludeJavaScriptLibrary({"${tapestry.scriptaculous}/prototype.js","${tacos.datejs}/date.js","${tacos}/tacos.js"})
25  public class DateJS {
26  	
27      @Parameter(defaultPrefix = TapestryConstants.LITERAL_BINDING_PREFIX, name="format")
28      private String format = "MM/dd/yy";
29      
30      @Parameter(defaultPrefix = "message") 
31      private String message;
32       
33      @Environmental
34      private PageRenderSupport pageRenderSupport;
35      
36      @Inject
37      private ComponentResources resources;
38      
39      @Inject
40      private Messages messages;
41      
42      void afterRender(MarkupWriter writer){
43      	if(message==null){
44      		message=messages.get("invalid");
45      	}
46      	pageRenderSupport.addScript("new Tacos.Date('%s','%s','%s')", resources.getId(),format,message);
47  
48      }
49  }