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 7 import fr.improve.struts.taglib.layout.util.LayoutUtils; 8 import fr.improve.struts.taglib.layout.util.TagUtils; 9 13 public class CheckboxTag extends AbstractFieldTag { 14 org.apache.struts.taglib.html.CheckboxTag checkboxTag = new org.apache.struts.taglib.html.CheckboxTag(); 15 protected boolean doBeforeValue() { 16 fieldTag = checkboxTag; 17 return true; 18 } 19 public int doStartInspectField() throws JspException { 20 if (!doBeforeValue()) return SKIP_BODY; 22 23 doAfterValue(); 24 25 return EVAL_BODY_INCLUDE; 26 } 27 28 29 30 protected Object getFieldValue() throws JspException { 31 Object lc_value = value; 32 if (lc_value==null) lc_value = "on"; 33 switch (getFieldDisplayMode()) { 34 case MODE_EDIT : 35 break; 36 case MODE_NODISPLAY : 37 break; 38 case MODE_INSPECT : 39 return super.getFieldValue(); 40 } 41 return lc_value; 42 } 43 44 protected void doAfterValue() throws JspException { 45 Object lc_value = value; 46 if (lc_value==null) lc_value = "on"; 47 switch (getFieldDisplayMode()) { 48 case MODE_EDIT : 49 break; 50 case MODE_NODISPLAY : 51 break; 52 case MODE_INSPECT : 53 if (isChecked()) { 54 StringBuffer buffer = new StringBuffer (); 55 buffer.append("<img SRC=\""); 56 buffer.append(getSkin().getImageDirectory(pageContext.getRequest())); 57 buffer.append("/"); 58 buffer.append(getSkin().getProperty("layout.checkbox.checked")); 59 buffer.append("\" border=\"0\" alt=\""); 60 buffer.append(getSkin().getProperty("layout.checkbox.checked.label")); 61 buffer.append("\">"); 62 TagUtils.write(pageContext, buffer.toString()); 63 } else { 64 String lc_imgsrc = null; 65 String lc_label = "unchecked"; 66 try { 67 lc_imgsrc = getSkin().getProperty("layout.checkbox.unchecked"); 68 lc_label = getSkin().getProperty("layout.checkbox.unchecked.label"); 69 } catch(java.util.MissingResourceException me) { 70 } 72 if (null != lc_imgsrc && lc_imgsrc.length()!=0) { 73 StringBuffer buffer = new StringBuffer (); 74 buffer.append("<img SRC=\""); 75 buffer.append(getSkin().getImageDirectory(pageContext.getRequest())); 76 buffer.append("/"); 77 buffer.append(lc_imgsrc); 78 buffer.append("\" border=\"0\" alt=\""); 79 buffer.append(lc_label); 80 buffer.append("\">"); 81 TagUtils.write(pageContext, buffer.toString()); 82 } 83 } 84 } 85 } 86 89 protected void printSimpleHiddenValue(Object in_value) throws JspException { 90 if (isChecked()) { 92 super.printSimpleHiddenValue(in_value); 93 } 94 } 95 96 protected boolean isChecked() throws JspException { 97 Object lc_value = LayoutUtils.getBeanFromPageContext(pageContext, name, property); 98 return lc_value != null && (lc_value.toString().equals("on") || lc_value.toString().equals("yes") || lc_value.toString().equals("true")); 99 } 100 101 protected void copyProperties(BaseHandlerTag in_dest) throws JspException { 102 super.copyProperties(in_dest); 103 checkboxTag.setName(getName()); 104 checkboxTag.setProperty(getProperty()); 105 checkboxTag.setValue(getValue()); 106 checkboxTag.setReadonly(isReadonly()); 107 } 108 109 } 110 | Popular Tags |