1 18 19 package cowsultants.itracker.web.taglib; 20 21 import java.net.*; 22 import java.util.*; 23 import javax.servlet.*; 24 import javax.servlet.http.*; 25 import javax.servlet.jsp.JspException ; 26 import javax.servlet.jsp.tagext.TagSupport ; 27 28 import org.apache.struts.Globals; 29 import org.apache.struts.action.*; 30 import org.apache.struts.util.*; 31 32 import cowsultants.itracker.ejb.client.models.*; 33 import cowsultants.itracker.ejb.client.resources.*; 34 import cowsultants.itracker.ejb.client.util.*; 35 import cowsultants.itracker.web.util.*; 36 37 public final class FormatCustomFieldTag extends TagSupport { 38 public static final String DISPLAY_TYPE_EDIT = "edit"; 39 public static final String DISPLAY_TYPE_VIEW = "view"; 40 41 private CustomFieldModel field; 42 private String currentValue; 43 private String displayType; 44 private String formName; 45 46 public CustomFieldModel getField() { 47 return field; 48 } 49 50 public void setField(CustomFieldModel value) { 51 field = value; 52 } 53 54 public String getCurrentValue() { 55 return currentValue; 56 } 57 58 public void setCurrentValue(String value) { 59 currentValue = value; 60 } 61 62 public String getDisplayType() { 63 return displayType; 64 } 65 66 public void setDisplayType(String value) { 67 displayType = value; 68 } 69 70 public String getFormName() { 71 return formName; 72 } 73 74 public void setFormName(String value) { 75 formName = value; 76 } 77 78 public int doStartTag() throws JspException { 79 return SKIP_BODY; 80 } 81 82 public int doEndTag() throws JspException { 83 Locale currLocale = null; 84 85 if(field != null) { 86 HttpSession session = pageContext.getSession(); 87 if(session != null) { 88 currLocale = (Locale) session.getAttribute(Constants.LOCALE_KEY); 89 } 90 91 field.setLabels(currLocale); 92 93 StringBuffer buf = new StringBuffer (); 94 buf.append("<td class=\"" + (DISPLAY_TYPE_VIEW.equalsIgnoreCase(displayType) ? "editColumnTitle" : "editColumnText") +"\">"); 95 buf.append(field.getName() + ": "); 96 buf.append("</td>\n"); 97 buf.append("<td align=\"left\" class=\"editColumnText\">"); 98 if(DISPLAY_TYPE_VIEW.equalsIgnoreCase(displayType)) { 99 if(currentValue != null) { 100 buf.append((field.getFieldType() == CustomFieldUtilities.TYPE_LIST ? field.getOptionNameByValue(currentValue) : currentValue)); 101 } 102 } else { 103 Object requestValue = RequestUtils.lookup(pageContext, org.apache.struts.taglib.html.Constants.BEAN_KEY, "customFields(" + field.getId() + ")", null); 104 if(currentValue == null && requestValue != null) { 105 currentValue = requestValue.toString(); 106 } 107 108 if(field.getFieldType() == CustomFieldUtilities.TYPE_LIST) { 109 buf.append("<select name=\"customFields(" + field.getId() + ")\">\n"); 110 CustomFieldValueModel[] options = field.getOptions(); 111 for(int i = 0; i < options.length; i++) { 112 buf.append("<option value=\"" + options[i].getValue() + "\""); 113 buf.append((currentValue != null && currentValue.equals(options[i].getValue()) ? " selected=\"selected\"" : "")); 114 buf.append(">"); 115 buf.append(options[i].getName()); 116 buf.append("</option>\n"); 117 } 118 buf.append("</select>\n"); 119 } else if(field.getFieldType() == CustomFieldUtilities.TYPE_DATE) { 120 buf.append("<input type=\"text\" name=\"customFields(" + field.getId() +")\""); 121 buf.append((currentValue != null && ! currentValue.equals("") ? " value=\"" + currentValue + "\"" : "")); 122 buf.append("> "); 123 buf.append("<img onmouseup=\"toggleDatePicker('cf" + field.getId() + "','" + formName + ".customFields(" + field.getId() + ")')\" "); 124 buf.append("id=cf" + field.getId() + "Pos name=cf" + field.getId() + "Pos width=19 height=19 SRC=\""); 125 try { 126 buf.append(RequestUtils.computeURL(pageContext, null, null, "/images/calendar.gif", null, null, null, false)); 127 } catch(MalformedURLException murle) { 128 buf.append("images/calendar.gif"); 129 } 130 buf.append("\" align=\"top\" border=\"0\">"); 131 buf.append("<div id=\"cf" + field.getId() + "\" style=\"position:absolute;\"></div>"); 132 } else { 133 buf.append("<input type=\"text\" name=\"customFields(" + field.getId() +")\""); 134 buf.append((currentValue != null && ! currentValue.equals("") ? " value=\"" + currentValue + "\"" : "")); 135 buf.append(">"); 136 } 137 } 138 buf.append("</td>\n"); 139 140 ResponseUtils.write(pageContext, buf.toString()); 141 } 142 143 clearState(); 144 return (EVAL_PAGE); 145 } 146 147 public void release() { 148 super.release(); 149 clearState(); 150 } 151 152 private void clearState() { 153 field = null; 154 currentValue = null; 155 } 156 } 157 | Popular Tags |