1 package fr.improve.struts.taglib.layout.field; 2 3 import javax.servlet.jsp.JspException ; 4 5 import org.apache.struts.taglib.html.BaseHandlerTag; 6 import org.apache.struts.taglib.html.TextTag; 7 import org.apache.struts.util.ResponseUtils; 8 9 import fr.improve.struts.taglib.layout.el.Expression; 10 import fr.improve.struts.taglib.layout.formatter.FormatException; 11 import fr.improve.struts.taglib.layout.util.TagUtils; 12 16 public class TextFieldTag extends AbstractFieldTag { 17 private TextTag textFieldTag = new org.apache.struts.taglib.html.TextTag(); 18 19 22 protected String format; 23 24 27 protected String editFormat; 28 29 protected String jspFormat; 30 protected String jspEditFormat; 31 32 38 protected boolean doBeforeValue() throws javax.servlet.jsp.JspException { 39 fieldTag = textFieldTag; 40 return true; 41 } 42 45 protected java.lang.Object getFieldValue() throws JspException { 46 Object lc_value = super.getFieldValue(); 47 if (lc_value != null) { 48 switch (getFieldDisplayMode()) { 49 case MODE_EDIT: 50 if (editFormat!=null) try { 51 lc_value = getSkin().getFormatter().format(lc_value, editFormat, pageContext); 52 } catch (FormatException fe) { 53 TagUtils.saveException(pageContext, fe); 54 throw new JspException ("Format " + editFormat + "failed: " + fe.getMessage()); 55 } 56 break; 57 default: 58 if (format!=null) try { 59 lc_value = getSkin().getFormatter().format(lc_value, format, pageContext); 60 } catch (FormatException fe) { 61 TagUtils.saveException(pageContext, fe); 62 throw new JspException ("Format " + format + "failed: " + fe.getMessage()); 63 } 64 break; 65 } 66 } 67 return lc_value; 68 } 69 70 public int doStartInspectField() throws JspException { 71 if (!doBeforeValue()) 73 return SKIP_BODY; 74 75 Object lc_value = getFieldValue(); 76 if (lc_value != null) { 77 StringBuffer buffer = new StringBuffer (); 78 buffer.append("<span class=\""); 79 buffer.append(styleClass); 80 buffer.append("\">"); 81 if (format == null) { 82 if (filter) { 83 buffer.append(ResponseUtils.filter(lc_value.toString())); 84 } else { 85 buffer.append(lc_value.toString()); 86 } 87 } else { 88 buffer.append(lc_value); 89 } 90 buffer.append("</span>"); 91 TagUtils.write(pageContext, buffer.toString()); 92 } 93 94 doAfterValue(); 95 96 return EVAL_BODY_INCLUDE; 97 } 98 99 public void release() { 100 super.release(); 101 format = null; 102 editFormat = null; 103 } 104 public void setType(String type) { 105 format = type; 106 } 107 public void setEditType(String type) { 108 editFormat = type; 109 } 110 public String getType() { 111 return format; 112 } 113 114 protected void copyProperties(BaseHandlerTag in_dest) throws JspException { 115 super.copyProperties(in_dest); 116 textFieldTag.setCols(getCols()); 117 textFieldTag.setMaxlength(getMaxlength()); 118 textFieldTag.setProperty(getProperty()); 119 textFieldTag.setRows(getRows()); 120 textFieldTag.setValue(getValue()); 121 textFieldTag.setAccept(getAccept()); 122 textFieldTag.setName(getName()); 123 } 124 125 protected void initDynamicValues() { 126 super.initDynamicValues(); 127 128 jspFormat = format; 130 format = Expression.evaluate(format, pageContext); 131 132 jspEditFormat = editFormat; 134 editFormat = Expression.evaluate(editFormat, pageContext); 135 } 136 137 protected void reset() { 138 format = jspFormat; 140 jspFormat = null; 141 142 editFormat = jspEditFormat; 144 jspEditFormat = null; 145 146 super.reset(); 147 } 148 } 149 | Popular Tags |