View Javadoc
1   /*
2    * Copyright 2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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.kuali.ole.sys.document.web.renderers;
17  
18  import javax.servlet.jsp.JspException;
19  import javax.servlet.jsp.PageContext;
20  import javax.servlet.jsp.tagext.Tag;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.kuali.rice.kns.web.taglib.html.KNSTextTag;
24  import org.springframework.web.util.HtmlUtils;
25  
26  /**
27   * Represents a field rendered as a text field
28   */
29  public class TextRenderer extends FieldRendererBase {
30      private KNSTextTag tag = new KNSTextTag();
31  
32      /**
33       * cleans up the html:text tag 
34       * @see org.kuali.ole.sys.document.web.renderers.FieldRendererBase#clear()
35       */
36      @Override
37      public void clear() {
38          super.clear();
39          tag.setProperty(null);
40          tag.setTitle(null);
41          tag.setSize(null);
42          tag.setMaxlength(null);
43          tag.setOnblur(null);
44          tag.setStyleClass(null);
45          tag.setValue(null);
46          tag.setStyleId(null);
47          tag.setTabindex(null);
48      }
49  
50      /**
51       * Uses a struts html:text tag to render this field
52       * @see org.kuali.ole.sys.document.web.renderers.Renderer#render(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag)
53       */
54      public void render(PageContext pageContext, Tag parentTag) throws JspException {
55          tag.setPageContext(pageContext);
56          tag.setParent(parentTag);
57          tag.setProperty(getFieldName());
58          tag.setTitle(getAccessibleTitle());
59          tag.setSize(getFieldSize());
60          //tag.setTabIndex();
61          tag.setMaxlength(getFieldMaxLength());
62          final String onBlur = buildOnBlur();
63          if (!StringUtils.isBlank(onBlur)) {
64              tag.setOnblur(buildOnBlur());
65          }
66          tag.setStyleClass(getField().getStyleClass());
67  
68          tag.setValue(getField().getPropertyValue());
69          tag.setStyleId(getFieldName());
70          
71          tag.doStartTag();
72          tag.doEndTag();
73          
74          renderQuickFinderIfNecessary(pageContext, parentTag);
75          
76          if (isShowError()) {
77              renderErrorIcon(pageContext);
78          }
79      }
80      
81      /**
82       * Determines the max length of the field
83       * @return the max length of the field, formatted to a string
84       */
85      protected String getFieldMaxLength() {
86          return Integer.toString(getField().getMaxLength());
87      }
88  
89      /**
90       * Determines the size of the field
91       * @return the size of the field, formatted as a String
92       */
93      protected String getFieldSize() {
94          return Integer.toString(getField().getSize());
95      }
96  
97      /**
98       * Yes, I'd like a quickfinder please
99       * @see org.kuali.ole.sys.document.web.renderers.FieldRenderer#renderQuickfinder()
100      */
101     public boolean renderQuickfinder() {
102         return true;
103     }
104     
105 }