001/* 002 * Copyright 2010 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 1.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/ecl1.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 */ 016package org.kuali.ole.sys.document.web.renderers; 017 018import java.io.IOException; 019import java.util.List; 020 021import javax.servlet.jsp.JspException; 022import javax.servlet.jsp.JspWriter; 023import javax.servlet.jsp.PageContext; 024import javax.servlet.jsp.tagext.Tag; 025 026import org.kuali.rice.kns.web.ui.Field; 027 028/** 029 * Renders a set of read only fields to a table cell 030 */ 031public class MultipleReadOnlyFieldsRenderer implements Renderer { 032 private List<Field> fields; 033 private ReadOnlyRenderer readOnlyRenderer = new ReadOnlyRenderer(); 034 035 /** 036 * 037 * @see org.kuali.ole.sys.document.web.renderers.Renderer#clear() 038 */ 039 public void clear() { 040 fields = null; 041 } 042 043 /** 044 * 045 * @see org.kuali.ole.sys.document.web.renderers.Renderer#render(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag) 046 * KRAD Conversion: Customization of render with fieldsand inquiry urls. 047 */ 048 public void render(PageContext pageContext, Tag parentTag) throws JspException { 049 try { 050 JspWriter out = pageContext.getOut(); 051 if (fields != null && !fields.isEmpty()) { 052 out.write(beginReadOnlyLayout()); 053 for (Field field : fields) { 054 out.write(beginReadOnlyLabel()); 055 out.write(renderLabel(field)); 056 out.write(endReadOnlyLabel()); 057 out.write(beginReadOnlyValue()); 058 readOnlyRenderer.setField(field); 059 if (field.getInquiryURL() != null) { 060 readOnlyRenderer.setShouldRenderInquiry(true); 061 } 062 readOnlyRenderer.render(pageContext, parentTag); 063 readOnlyRenderer.clear(); 064 out.write(endReadOnlyValue()); 065 } 066 out.write(endReadOnlyLayout()); 067 } else { 068 out.write(renderEmptyCell()); 069 } 070 } 071 catch (IOException ioe) { 072 throw new JspException("Could not render MultipleReadOnlyFields", ioe); 073 } 074 } 075 076 /** 077 * @return the value to render for an empty cell 078 */ 079 protected String renderEmptyCell() { 080 return " "; 081 } 082 083 protected String beginReadOnlyLayout() { 084 return "<table>"; 085 } 086 087 protected String beginReadOnlyLabel() { 088 return "<tr><td width=\"50%\">"; 089 } 090 091 protected String endReadOnlyLabel() { 092 return "</td>"; 093 } 094 095 protected String beginReadOnlyValue() { 096 return "<td width=\"50%\">"; 097 } 098 099 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}