1 31 32 package org.opencms.widgets; 33 34 import org.opencms.file.CmsObject; 35 import org.opencms.util.CmsStringUtil; 36 import org.opencms.xml.types.CmsXmlBooleanValue; 37 38 import java.util.Map ; 39 40 49 public class CmsCheckboxWidget extends A_CmsWidget { 50 51 52 public static final String HIDDEN_SUFFIX = ".value"; 53 54 57 public CmsCheckboxWidget() { 58 59 this(""); 61 } 62 63 68 public CmsCheckboxWidget(String configuration) { 69 70 super(configuration); 71 } 72 73 76 public String getDialogWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) { 77 78 StringBuffer result = new StringBuffer (16); 79 80 result.append("<td class=\"xmlTd\">"); 81 result.append("<input type=\"checkbox\" name=\""); 82 result.append(param.getId()); 83 result.append("\" value=\"true\""); 84 boolean booleanValue = CmsXmlBooleanValue.getBooleanValue(cms, param); 85 if (booleanValue) { 86 result.append(" checked=\"checked\""); 87 } 88 result.append(">"); 89 result.append("<input type=\"hidden\" name=\""); 90 result.append(param.getId()); 91 result.append(HIDDEN_SUFFIX); 92 result.append("\" value=\""); 93 result.append(booleanValue); 94 result.append("\">"); 95 result.append("</td>"); 96 97 return result.toString(); 98 } 99 100 103 public I_CmsWidget newInstance() { 104 105 return new CmsCheckboxWidget(getConfiguration()); 106 } 107 108 111 public void setEditorValue( 112 CmsObject cms, 113 Map formParameters, 114 I_CmsWidgetDialog widgetDialog, 115 I_CmsWidgetParameter param) { 116 117 String [] values = (String [])formParameters.get(param.getId()); 118 if ((values != null) && (values.length > 0)) { 119 120 boolean booleanValue = CmsXmlBooleanValue.getBooleanValue(cms, param); 122 123 String formValue = values[0].trim(); 125 if (CmsStringUtil.isNotEmpty(formValue)) { 126 booleanValue = Boolean.valueOf(formValue).booleanValue(); 127 } 128 129 param.setStringValue(cms, String.valueOf(booleanValue)); 131 132 } else { 133 String value; 134 values = (String [])formParameters.get(param.getId() + HIDDEN_SUFFIX); 135 if ((values != null) && (values.length > 0)) { 136 value = Boolean.FALSE.toString(); 138 } else { 139 value = param.getDefault(cms); 141 } 142 param.setStringValue(cms, value); 143 } 144 } 145 } | Popular Tags |