View Javadoc
1   /*
2    * Copyright 2010 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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  import java.util.List;
20  
21  import javax.servlet.jsp.JspException;
22  import javax.servlet.jsp.JspWriter;
23  import javax.servlet.jsp.PageContext;
24  import javax.servlet.jsp.tagext.Tag;
25  
26  import org.kuali.rice.kns.web.ui.Field;
27  
28  /**
29   * Renders a set of read only fields to a table cell
30   */
31  public class MultipleReadOnlyFieldsRenderer implements Renderer {
32      private List<Field> fields;
33      private ReadOnlyRenderer readOnlyRenderer = new ReadOnlyRenderer();
34  
35      /**
36       * 
37       * @see org.kuali.ole.sys.document.web.renderers.Renderer#clear()
38       */
39      public void clear() {
40          fields = null;
41      }
42  
43      /**
44       * 
45       * @see org.kuali.ole.sys.document.web.renderers.Renderer#render(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag)
46       * KRAD Conversion: Customization of render with fieldsand inquiry urls.
47       */
48      public void render(PageContext pageContext, Tag parentTag) throws JspException {
49          try {
50              JspWriter out = pageContext.getOut();
51              if (fields != null && !fields.isEmpty()) {
52                  out.write(beginReadOnlyLayout());
53                  for (Field field : fields) {
54                      out.write(beginReadOnlyLabel());
55                      out.write(renderLabel(field));
56                      out.write(endReadOnlyLabel());
57                      out.write(beginReadOnlyValue());
58                      readOnlyRenderer.setField(field);
59                      if (field.getInquiryURL() != null) {
60                          readOnlyRenderer.setShouldRenderInquiry(true);
61                      }
62                      readOnlyRenderer.render(pageContext, parentTag);
63                      readOnlyRenderer.clear();
64                      out.write(endReadOnlyValue());
65                  }
66                  out.write(endReadOnlyLayout());
67              } else {
68                  out.write(renderEmptyCell());
69              }
70          }
71          catch (IOException ioe) {
72              throw new JspException("Could not render MultipleReadOnlyFields", ioe);
73          }
74      }
75      
76      /**
77       * @return the value to render for an empty cell
78       */
79      protected String renderEmptyCell() {
80          return "&nbsp;";
81      }
82      
83      protected String beginReadOnlyLayout() {
84          return "<table>";
85      }
86      
87      protected String beginReadOnlyLabel() {
88          return "<tr><td width=\"50%\">";
89      }
90      
91      protected String endReadOnlyLabel() {
92          return "</td>";
93      }
94      
95      protected String beginReadOnlyValue() {
96          return "<td width=\"50%\">";
97      }
98      
99      protected String endReadOnlyValue() {
100         return "</td></tr>";
101     }
102 
103     /**
104      * KRAD Conversion: getting field label
105      */
106     protected String renderLabel(Field field) {
107         return field.getFieldLabel();
108     }
109     
110     protected String endReadOnlyLayout() {
111         return "</table>";
112     }
113 
114     /**
115      * @return the current list of fields to render through this render pass
116      *
117      * KRAD Conversion: getting fields
118      */
119     public List<Field> getFields() {
120         return fields;
121     }
122 
123     /**
124      * Associate fields with this render pass of the renderer
125      * @param fields the fields to render through this render pass
126      *
127      * KRAD Conversion: setting fields
128      */
129     public void setFields(List<Field> fields) {
130         this.fields = fields;
131     }
132 
133 }