001/** 002 * Copyright 2005-2015 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.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/ecl2.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.rice.krad.uif.control; 017 018import org.kuali.rice.krad.datadictionary.parse.BeanTag; 019import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute; 020import org.kuali.rice.krad.datadictionary.validator.ErrorReport; 021import org.kuali.rice.krad.datadictionary.validator.ValidationTrace; 022import org.kuali.rice.krad.uif.component.Component; 023import org.kuali.rice.krad.uif.element.Message; 024import org.kuali.rice.krad.uif.util.ComponentFactory; 025import org.kuali.rice.krad.uif.view.View; 026 027import java.util.ArrayList; 028import java.util.List; 029 030/** 031 * Represents a HTML Checkbox control. Typically used for boolean attributes (where the 032 * value is either on/off, true/false) 033 * 034 * @author Kuali Rice Team (rice.collab@kuali.org) 035 */ 036@BeanTag(name = "checkboxControl-bean", parent = "Uif-CheckboxControl") 037public class CheckboxControl extends ControlBase implements ValueConfiguredControl { 038 private static final long serialVersionUID = -1397028958569144230L; 039 040 private String value; 041 private String checkboxLabel; 042 043 private Message richLabelMessage; 044 private List<Component> inlineComponents; 045 046 public CheckboxControl() { 047 super(); 048 } 049 050 /** 051 * Sets up rich message content for the label, if any exists 052 * 053 * @see Component#performApplyModel(org.kuali.rice.krad.uif.view.View, Object, org.kuali.rice.krad.uif.component.Component) 054 */ 055 @Override 056 public void performApplyModel(View view, Object model, Component parent) { 057 super.performApplyModel(view, model, parent); 058 059 if (richLabelMessage == null) { 060 Message message = ComponentFactory.getMessage(); 061 view.assignComponentIds(message); 062 message.setMessageText(checkboxLabel); 063 message.setInlineComponents(inlineComponents); 064 message.setGenerateSpan(false); 065 view.getViewHelperService().performComponentInitialization(view, model, message); 066 this.setRichLabelMessage(message); 067 } 068 } 069 070 /** 071 * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle() 072 */ 073 @Override 074 public List<Component> getComponentsForLifecycle() { 075 List<Component> components = super.getComponentsForLifecycle(); 076 077 components.add(richLabelMessage); 078 079 return components; 080 } 081 082 /** 083 * The value that will be submitted when the checkbox control is checked 084 * 085 * <p> 086 * Value can be left blank, in which case the checkbox will submit a boolean value that 087 * will populate a boolean property. In cases where the checkbox needs to submit another value (for 088 * instance possibly in the checkbox group) the value can be set which will override the default. 089 * </p> 090 * 091 * @return value for checkbox 092 */ 093 @BeanTagAttribute(name="value") 094 public String getValue() { 095 return value; 096 } 097 098 /** 099 * Setter for the value that should be submitted when the checkbox is checked 100 * 101 * @param value 102 */ 103 public void setValue(String value) { 104 this.value = value; 105 } 106 107 /** 108 * Returns the label text for this checkbox 109 * 110 * @return the checkbox label text 111 */ 112 @BeanTagAttribute(name="checkboxLabel") 113 public String getCheckboxLabel() { 114 return checkboxLabel; 115 } 116 117 /** 118 * Sets the label text for this checkbox 119 * 120 * @param checkboxLabel the label text 121 */ 122 public void setCheckboxLabel(String checkboxLabel) { 123 this.checkboxLabel = checkboxLabel; 124 } 125 126 /** 127 * Gets the Message that represents the rich message content of the label if labelText is using rich message tags. 128 * <b>DO NOT set this 129 * property directly unless you need full control over the message structure.</b> 130 * 131 * @return Message with rich message structure, null if no rich message structure 132 */ 133 @BeanTagAttribute(name="richLabelMessage",type= BeanTagAttribute.AttributeType.SINGLEBEAN) 134 public Message getRichLabelMessage() { 135 return richLabelMessage; 136 } 137 138 /** 139 * Sets the Message that represents the rich message content of the label if it is using rich message tags. <b>DO 140 * NOT set this 141 * property directly unless you need full control over the message structure.</b> 142 * 143 * @param richLabelMessage 144 */ 145 public void setRichLabelMessage(Message richLabelMessage) { 146 this.richLabelMessage = richLabelMessage; 147 } 148 149 /** 150 * Gets the inlineComponents used by index in the checkboxLabel that has rich message component index tags 151 * 152 * @return the Label's inlineComponents 153 */ 154 @BeanTagAttribute(name="inlineComponents",type= BeanTagAttribute.AttributeType.LISTBEAN) 155 public List<Component> getInlineComponents() { 156 return inlineComponents; 157 } 158 159 /** 160 * Sets the inlineComponents used by index in the checkboxLabel that has rich message component index tags 161 * 162 * @param inlineComponents 163 */ 164 public void setInlineComponents(List<Component> inlineComponents) { 165 this.inlineComponents = inlineComponents; 166 } 167 168 /** 169 * @see org.kuali.rice.krad.uif.component.ComponentBase#copy() 170 */ 171 @Override 172 protected <T> void copyProperties(T component) { 173 super.copyProperties(component); 174 CheckboxControl checkboxControlCopy = (CheckboxControl) component; 175 checkboxControlCopy.setValue(this.value); 176 checkboxControlCopy.setCheckboxLabel(this.checkboxLabel); 177 178 if (this.richLabelMessage != null) { 179 checkboxControlCopy.setRichLabelMessage((Message)this.richLabelMessage.copy()); 180 } 181 182 if(inlineComponents != null) { 183 List<Component> inlineComponentsCopy = new ArrayList<Component>(); 184 for(Component inlineComponent : inlineComponents) { 185 inlineComponentsCopy.add((Component)inlineComponent.copy()); 186 } 187 checkboxControlCopy.setInlineComponents(inlineComponentsCopy); 188 } 189 } 190 191 /** 192 * @see org.kuali.rice.krad.uif.component.Component#completeValidation 193 */ 194 @Override 195 public void completeValidation(ValidationTrace tracer){ 196 tracer.addBean(this); 197 198 super.completeValidation(tracer.getCopy()); 199 } 200}