View Javadoc

1   /**
2    * This file is part of the equanda project.
3    *
4    * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at http://www.mozilla.org/MPL/
7    *
8    * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
9    * ANY KIND, either express or implied. See the License for the specific language governing rights and
10   * limitations under the License.
11   *
12   * Alternatively, the contents of this file may be used under the terms of
13   * either the GNU General Public License Version 2 or later (the "GPL"), or
14   * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
15   * in which case the provisions of the GPL or the LGPL are applicable instead
16   * of those above. If you wish to allow use of your version of this file only
17   * under the terms of either the GPL or the LGPL, and not to allow others to
18   * use your version of this file under the terms of the MPL, indicate your
19   * decision by deleting the provisions above and replace them with the notice
20   * and other provisions required by the GPL or the LGPL. If you do not delete
21   * the provisions above, a recipient may use your version of this file under
22   * the terms of any one of the MPL, the GPL or the LGPL.
23   */
24  
25  package org.equanda.tapestry5.components;
26  
27  import org.apache.tapestry5.ComponentResources;
28  import org.apache.tapestry5.Link;
29  import org.apache.tapestry5.annotations.BeginRender;
30  import org.apache.tapestry5.annotations.CleanupRender;
31  import org.apache.tapestry5.ioc.annotations.Inject;
32  import org.apache.tapestry5.services.Environment;
33  
34  import java.util.ArrayList;
35  import java.util.List;
36  
37  /**
38   * FormSupport which can contain FormActionLink components and has special provisions for assuring
39   * actions can maintain (server side) state inside loops.
40   *
41   * @author <a href="mailto:joachim@progs.be">Joachim Van der Auwera</a>
42   */
43  public class FormSupport
44  {
45      @Inject
46      private ComponentResources resources;
47  
48      @Inject
49      private Environment environment;    
50  
51      private String formActionLinkTarget;
52  
53      @BeginRender
54      Object begin()
55      {
56          environment.push( FormSupport.class, this );
57          return true;
58      }
59  
60      @CleanupRender
61      void cleanupRender()
62      {
63          environment.pop( FormSupport.class );
64      }
65  
66  
67      public String getFormActionLinkTarget()
68      {
69          return formActionLinkTarget;
70      }
71  
72      public void setFormActionLinkTarget( String formActionLinkTarget )
73      {
74          this.formActionLinkTarget = formActionLinkTarget;
75      }
76  
77      public boolean hasLinkTarget()
78      {
79          return formActionLinkTarget != null && !"".equals( formActionLinkTarget );
80      }
81  
82      public Link getLinkTarget()
83      {
84          if ( hasLinkTarget() )
85          {
86              return new FormLink( formActionLinkTarget );
87          }
88          return null;
89      }
90  
91      class FormLink
92          implements Link
93      {
94          private String target;
95  
96          public FormLink( String target )
97          {
98              this.target = target;
99          }
100 
101         public List<String> getParameterNames()
102         {
103             return new ArrayList<String>();
104         }
105 
106         public String getParameterValue( String s )
107         {
108             return null;
109         }
110 
111         public void addParameter( String s, String s1 ) {/*ignore*/}
112 
113         public String toURI() { return target; }
114 
115         public String toRedirectURI() { return target; }
116 
117         public String getAnchor()
118         {
119             return null;
120         }
121 
122         public void setAnchor( String s ) {/*ignore*/}
123 
124         public String toAbsoluteURI() { return target;}
125     }
126 }