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 java.io.IOException;
19  
20  import javax.servlet.jsp.JspException;
21  import javax.servlet.jsp.JspWriter;
22  import javax.servlet.jsp.PageContext;
23  import javax.servlet.jsp.tagext.Tag;
24  
25  import org.apache.commons.lang.StringUtils;
26  import org.apache.struts.taglib.html.HiddenTag;
27  import org.springframework.web.util.HtmlUtils;
28  
29  /**
30   * Renders the dynamic label portion of a field
31   */
32  public class DynamicNameLabelRenderer implements Renderer {
33      private String fieldName = null;
34      private String fieldValue = null;
35      private HiddenTag valuePersistingTag = new HiddenTag();
36      
37      /**
38       * @see org.kuali.ole.sys.document.web.renderers.Renderer#clear()
39       */
40      public void clear() {
41          fieldName = null;
42          fieldValue = null;
43          
44          valuePersistingTag.setPageContext(null);
45          valuePersistingTag.setParent(null);
46          valuePersistingTag.setProperty(null);
47          valuePersistingTag.setValue(null);
48      }
49  
50      /**
51       * 
52       * @see org.kuali.ole.sys.document.web.renderers.Renderer#render(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag, org.kuali.rice.krad.bo.BusinessObject)
53       */
54      public void render(PageContext pageContext, Tag parentTag) throws JspException {
55          JspWriter out = pageContext.getOut();
56          try {
57              out.write("<br />");
58              out.write("<div id=\""+fieldName+".div\" class=\"fineprint\">");
59              if (!StringUtils.isBlank(fieldValue)) {
60                  out.write(fieldValue);
61              }
62              out.write("</div>");
63              
64              if (!StringUtils.isBlank(fieldValue)) {
65                  renderValuePersistingTag(pageContext, parentTag);
66              }
67          }
68          catch (IOException ioe) {
69              throw new JspException("Difficulty rendering a dynamic field label", ioe);
70          }
71      }
72      
73      /**
74       * If the value is present, renders that value in a tag
75       * @param pageContext the page context to render to
76       * @param parentTag the tag requesting all this rendering
77       */
78      protected void renderValuePersistingTag(PageContext pageContext, Tag parentTag) throws JspException {
79          valuePersistingTag.setPageContext(pageContext);
80          valuePersistingTag.setParent(parentTag);
81          valuePersistingTag.setProperty(fieldName);
82          valuePersistingTag.setValue(fieldValue);
83          
84          valuePersistingTag.doStartTag();
85          valuePersistingTag.doEndTag();
86      }
87  
88      /**
89       * Gets the fieldName attribute. 
90       * @return Returns the fieldName.
91       */
92      public String getFieldName() {
93          return fieldName;
94      }
95  
96      /**
97       * Sets the fieldName attribute value.
98       * @param fieldName The fieldName to set.
99       */
100     public void setFieldName(String fieldName) {
101         this.fieldName = fieldName;
102     }
103 
104     /**
105      * Gets the fieldValue attribute. 
106      * @return Returns the fieldValue.
107      */
108     public String getFieldValue() {
109         return fieldValue;
110     }
111 
112     /**
113      * Sets the fieldValue attribute value.
114      * @param fieldValue The fieldValue to set.
115      */
116     public void setFieldValue(String fieldValue) {
117         this.fieldValue = fieldValue;
118     }
119 }