View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.sys.document.web.renderers;
20  
21  import javax.servlet.jsp.JspException;
22  import javax.servlet.jsp.PageContext;
23  import javax.servlet.jsp.tagext.Tag;
24  
25  import org.apache.commons.lang.StringUtils;
26  import org.kuali.rice.kns.web.taglib.html.KNSTextTag;
27  import org.springframework.web.util.HtmlUtils;
28  
29  /**
30   * Represents a field rendered as a text field
31   */
32  public class TextRenderer extends FieldRendererBase {
33      private KNSTextTag tag = new KNSTextTag();
34  
35      /**
36       * cleans up the html:text tag 
37       * @see org.kuali.kfs.sys.document.web.renderers.FieldRendererBase#clear()
38       */
39      @Override
40      public void clear() {
41          super.clear();
42          tag.setProperty(null);
43          tag.setTitle(null);
44          tag.setSize(null);
45          tag.setMaxlength(null);
46          tag.setOnblur(null);
47          tag.setStyleClass(null);
48          tag.setValue(null);
49          tag.setStyleId(null);
50          tag.setTabindex(null);
51      }
52  
53      /**
54       * Uses a struts html:text tag to render this field
55       * @see org.kuali.kfs.sys.document.web.renderers.Renderer#render(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag)
56       */
57      public void render(PageContext pageContext, Tag parentTag) throws JspException {
58          tag.setPageContext(pageContext);
59          tag.setParent(parentTag);
60          tag.setProperty(getFieldName());
61          tag.setTitle(getAccessibleTitle());
62          tag.setSize(getFieldSize());
63          //tag.setTabIndex();
64          tag.setMaxlength(getFieldMaxLength());
65          final String onBlur = buildOnBlur();
66          if (!StringUtils.isBlank(onBlur)) {
67              tag.setOnblur(buildOnBlur());
68          }
69          tag.setStyleClass(getField().getStyleClass());
70  
71          tag.setValue(getField().getPropertyValue());
72          tag.setStyleId(getFieldName());
73          
74          tag.doStartTag();
75          tag.doEndTag();
76          
77          renderQuickFinderIfNecessary(pageContext, parentTag);
78          
79          if (isShowError()) {
80              renderErrorIcon(pageContext);
81          }
82      }
83      
84      /**
85       * Determines the max length of the field
86       * @return the max length of the field, formatted to a string
87       */
88      protected String getFieldMaxLength() {
89          return Integer.toString(getField().getMaxLength());
90      }
91  
92      /**
93       * Determines the size of the field
94       * @return the size of the field, formatted as a String
95       */
96      protected String getFieldSize() {
97          return Integer.toString(getField().getSize());
98      }
99  
100     /**
101      * Yes, I'd like a quickfinder please
102      * @see org.kuali.kfs.sys.document.web.renderers.FieldRenderer#renderQuickfinder()
103      */
104     public boolean renderQuickfinder() {
105         return true;
106     }
107     
108 }