001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.sys.document.web.renderers;
017
018 import javax.servlet.jsp.JspException;
019 import javax.servlet.jsp.PageContext;
020 import javax.servlet.jsp.tagext.Tag;
021
022 import org.apache.commons.lang.StringUtils;
023 import org.kuali.rice.kns.web.taglib.html.KNSTextTag;
024 import org.springframework.web.util.HtmlUtils;
025
026 /**
027 * Represents a field rendered as a text field
028 */
029 public class TextRenderer extends FieldRendererBase {
030 private KNSTextTag tag = new KNSTextTag();
031
032 /**
033 * cleans up the html:text tag
034 * @see org.kuali.kfs.sys.document.web.renderers.FieldRendererBase#clear()
035 */
036 @Override
037 public void clear() {
038 super.clear();
039 tag.setProperty(null);
040 tag.setTitle(null);
041 tag.setSize(null);
042 tag.setMaxlength(null);
043 tag.setOnblur(null);
044 tag.setStyleClass(null);
045 tag.setValue(null);
046 tag.setStyleId(null);
047 tag.setTabindex(null);
048 }
049
050 /**
051 * Uses a struts html:text tag to render this field
052 * @see org.kuali.kfs.sys.document.web.renderers.Renderer#render(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag)
053 */
054 public void render(PageContext pageContext, Tag parentTag) throws JspException {
055 tag.setPageContext(pageContext);
056 tag.setParent(parentTag);
057 tag.setProperty(getFieldName());
058 tag.setTitle(getAccessibleTitle());
059 tag.setSize(getFieldSize());
060 //tag.setTabIndex();
061 tag.setMaxlength(getFieldMaxLength());
062 final String onBlur = buildOnBlur();
063 if (!StringUtils.isBlank(onBlur)) {
064 tag.setOnblur(buildOnBlur());
065 }
066 tag.setStyleClass(getField().getStyleClass());
067
068 tag.setValue(HtmlUtils.htmlEscape(getField().getPropertyValue()));
069 tag.setStyleId(getFieldName());
070
071 tag.doStartTag();
072 tag.doEndTag();
073
074 renderQuickFinderIfNecessary(pageContext, parentTag);
075
076 if (isShowError()) {
077 renderErrorIcon(pageContext);
078 }
079 }
080
081 /**
082 * Determines the max length of the field
083 * @return the max length of the field, formatted to a string
084 */
085 protected String getFieldMaxLength() {
086 return Integer.toString(getField().getMaxLength());
087 }
088
089 /**
090 * Determines the size of the field
091 * @return the size of the field, formatted as a String
092 */
093 protected String getFieldSize() {
094 return Integer.toString(getField().getSize());
095 }
096
097 /**
098 * Yes, I'd like a quickfinder please
099 * @see org.kuali.kfs.sys.document.web.renderers.FieldRenderer#renderQuickfinder()
100 */
101 public boolean renderQuickfinder() {
102 return true;
103 }
104
105 }