001 /** 002 * Copyright 2005-2013 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 */ 016 package org.kuali.rice.krad.uif.control; 017 018 import org.kuali.rice.krad.datadictionary.parse.BeanTag; 019 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute; 020 import org.kuali.rice.krad.datadictionary.validator.ErrorReport; 021 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace; 022 import org.kuali.rice.krad.uif.component.Component; 023 import org.kuali.rice.krad.uif.element.Message; 024 import org.kuali.rice.krad.uif.util.ComponentFactory; 025 import org.kuali.rice.krad.uif.view.View; 026 027 import java.util.ArrayList; 028 import 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") 037 public 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.Component#completeValidation 170 */ 171 @Override 172 public void completeValidation(ValidationTrace tracer){ 173 tracer.addBean(this); 174 175 super.completeValidation(tracer.getCopy()); 176 } 177 }