Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/aendvari/tethys/tag/html/AbstractFieldTag.java


1   /*
2    * AbstractFieldTag.java
3    *
4    * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved.
5    *
6    * See the file LICENSE for terms of use.
7    *
8    */
9   
10  package com.aendvari.tethys.tag.html;
11  
12  import java.io.*;
13  
14  import javax.servlet.*;
15  import javax.servlet.http.*;
16  import javax.servlet.jsp.*;
17  import javax.servlet.jsp.tagext.*;
18  
19  import com.aendvari.common.model.*;
20  import com.aendvari.tethys.tag.*;
21  import com.aendvari.tethys.context.*;
22  
23  
24  /**
25   * This is a base class for the various input tags for text fields.
26   *
27   * @author Scott Milne
28   * 
29   */
30  
31  public abstract class AbstractFieldTag extends AbstractInputTag
32  {
33      /** The name of this field. */
34      protected String name;
35  
36      /** The HTML <code>type</code> attribute. */
37      protected String type;
38  
39  
40    /* Accessors */
41    
42    public String getName() { return name; }
43    public void setName(String param) { name = param; }
44  
45    public String getId() { return name; }
46    public void setId(String param) { name = param; }
47  
48    public String getType() { return type; }
49    public void setType(String param) { type = param; }
50  
51  
52  
53      public int doStartTag() throws JspException
54      {
55        try
56        {
57        StringBuffer tagString = new StringBuffer("<input");
58  
59        tagString.append(" type=\"");
60        tagString.append(type);
61        tagString.append("\"");
62  
63        // if no name is given, use the path
64        if (name == null)
65        {
66          // establish tag context
67          establishModelContext();
68  
69          // build the name from the current context plus the path
70          name = modelContext.extendModelPath(getPath());
71  
72          // for visual purposes, convert all "." into "/"
73          // OSM supports both, but it looks better to have all the same
74          name = name.replace('.', '/');
75        }
76  
77        tagString.append(" name=\"");
78        tagString.append(name);
79        tagString.append("\"");
80  
81        
82        if (getMaxlength() != null)
83        {
84          tagString.append(" maxlength=\"");
85          tagString.append(getMaxlength());
86          tagString.append("\"");
87        }
88  
89        if (getCols() != null)
90        {
91          tagString.append(" size=\"");
92          tagString.append(getCols());
93          tagString.append("\"");
94        }
95  
96        if (getAccesskey() != null)
97        {
98          tagString.append(" accesskey=\"");
99          tagString.append(getAccesskey());
100         tagString.append("\"");
101       }
102 
103       if (getTabindex() != null)
104       {
105         tagString.append(" tabindex=\"");
106         tagString.append(getTabindex());
107         tagString.append("\"");
108       }
109 
110       // add the extra attributes (if any were defined)
111       tagString.append(generateScriptAttribtues());
112       tagString.append(generateStyleAttribute());
113 
114       // append the value
115       tagString.append(" value=\"");
116 
117       if (getValue() != null)
118       {
119         tagString.append(getValue());
120       }
121       else if(getPath() != null)
122       {
123         tagString.append(extractModelValue(getPath()));
124       }
125       else
126       {
127         throw new JspTagException("AbstractFieldTag[" + type + "] Error: You must have either a \"path\" or a \"value\" attribute.");
128       }
129 
130       tagString.append("\"");
131 
132       // finish off the tag
133       tagString.append(">");
134 
135       // print out the finalized string
136       pageContext.getOut().write(tagString.toString());
137     }
138     catch (Exception e)
139     {
140       throw new JspTagException("AbstractFieldTag[" + type + "] Error:" + e.toString());
141     }
142 
143     //
144     // COMPATIBILITY NOTICE
145     //
146     // If you are using JSP 1.1, this value is non-functional, use the following instead:
147     //
148     // EVAL_BODY_TAG
149     //
150     return EVAL_BODY_BUFFERED;
151     }
152 
153     public int doEndTag() throws JspException
154     {
155     if (bodyContent == null)
156     {
157       return EVAL_PAGE;
158     }
159 
160     try
161     {
162       pageContext.getOut().println(bodyContent.getString().trim());
163     }
164     catch (IOException e)
165     {
166       throw new JspTagException("CheckboxTag Error:" + e.toString());
167     }
168 
169     // Continue evaluating this page
170     return EVAL_PAGE;
171     }
172 
173     public void release()
174     {
175     super.release();
176     name = null;
177     type = null;
178     }
179 }
180