View Javadoc

1   /*
2    * Copyright 2004 Jeff Johnston
3    *
4    * Licensed under the Apache License, Version 2.0 (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
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.extremecomponents.table.tag;
17  
18  import javax.servlet.jsp.JspException;
19  import javax.servlet.jsp.tagext.TagSupport;
20  
21  import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
22  import org.extremecomponents.table.FormAttributes;
23  import org.extremecomponents.table.bean.Form;
24  
25  
26  
27  /***
28   * @author jeff johnston
29   */
30  public class FormTag extends TagSupport implements FormAttributes
31  {
32  	private String name;
33  	private String action;
34  	private String method;
35  	private String onsubmit;
36  
37  	public String getName()
38  	{
39  		return name;
40  	}
41  
42  	public void setName(String name)
43  	{
44  		this.name = name;
45  	}
46  
47  	public String getAction()
48  	{
49  		return action;
50  	}
51  
52  	public void setAction(String action)
53  	{
54  		this.action = action;
55  	}
56  
57  	public String getMethod() 
58  	{
59  		return method;
60  	}
61  
62  	public void setMethod(String method) 
63  	{
64  		this.method = method;
65  	}
66  
67  	public String getOnsubmit()
68  	{
69  		return onsubmit;
70  	}
71  
72  	public void setOnsubmit(String onsubmit)
73  	{
74  		this.onsubmit = onsubmit;
75  	}
76  
77  	public int doStartTag()
78  		throws JspException
79  	{
80  		TableTag tableTag = (TableTag) findAncestorWithClass(this, TableTag.class);
81  
82  		if (tableTag.getModelRowsSize() > 0) //only go through the first pass
83  		{
84  			return SKIP_BODY;
85  		}
86  		
87  		if (action != null)
88  		{
89  			action = (String) ExpressionEvaluatorManager.evaluate("action", action, String.class, this, pageContext);
90  		}
91  		
92  		Form form = new Form(tableTag.getModel()); //first create the form
93  		form.setName(name);
94  		form.setAction(action);
95  		form.setMethod(method);
96  		form.setOnsubmit(onsubmit);
97  		tableTag.addForm(form);
98  		
99  		cleanup();
100 
101 		return EVAL_BODY_INCLUDE;
102 	}
103 	
104 	public void cleanup()
105 	{
106 		name = null;
107 		action = null;
108 		method = null;
109 		onsubmit = null;
110 	}	
111 }