001/** 002 * Copyright 2005-2016 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 java.util.List; 019 020import org.kuali.rice.krad.datadictionary.parse.BeanTag; 021import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute; 022import org.kuali.rice.krad.datadictionary.validator.ValidationTrace; 023import org.kuali.rice.krad.uif.component.Component; 024import org.kuali.rice.krad.uif.element.Message; 025import org.kuali.rice.krad.uif.util.ComponentFactory; 026import org.kuali.rice.krad.uif.util.ComponentUtils; 027import org.kuali.rice.krad.uif.util.LifecycleElement; 028 029/** 030 * Represents a HTML Checkbox control. Typically used for boolean attributes (where the 031 * value is either on/off, true/false) 032 * 033 * @author Kuali Rice Team (rice.collab@kuali.org) 034 */ 035@BeanTag(name = "checkboxControl", parent = "Uif-CheckboxControl") 036public class CheckboxControl extends ControlBase implements ValueConfiguredControl { 037 private static final long serialVersionUID = -1397028958569144230L; 038 039 private String value; 040 private String checkboxLabel; 041 private boolean checked; 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 * {@inheritDoc} 054 */ 055 @Override 056 public void performApplyModel(Object model, LifecycleElement parent) { 057 super.performApplyModel(model, parent); 058 059 if (richLabelMessage == null) { 060 Message message = ComponentFactory.getMessage(); 061 message.setMessageText(checkboxLabel); 062 message.setInlineComponents(inlineComponents); 063 message.setRenderWrapperTag(false); 064 this.setRichLabelMessage(message); 065 } 066 } 067 068 /** 069 * The value that will be submitted when the checkbox control is checked 070 * 071 * <p> 072 * Value can be left blank, in which case the checkbox will submit a boolean value that 073 * will populate a boolean property. In cases where the checkbox needs to submit another value (for 074 * instance possibly in the checkbox group) the value can be set which will override the default. 075 * </p> 076 * 077 * @return value for checkbox 078 */ 079 @BeanTagAttribute 080 public String getValue() { 081 return value; 082 } 083 084 /** 085 * Setter for the value that should be submitted when the checkbox is checked 086 * 087 * @param value 088 */ 089 public void setValue(String value) { 090 this.value = value; 091 } 092 093 /** 094 * Returns the label text for this checkbox 095 * 096 * @return the checkbox label text 097 */ 098 @BeanTagAttribute 099 public String getCheckboxLabel() { 100 return checkboxLabel; 101 } 102 103 /** 104 * Sets the label text for this checkbox 105 * 106 * @param checkboxLabel the label text 107 */ 108 public void setCheckboxLabel(String checkboxLabel) { 109 this.checkboxLabel = checkboxLabel; 110 } 111 112 /** 113 * Sets the checked state. 114 * 115 * @param checked - boolean true = checked, false = not checked 116 */ 117 public void setChecked(boolean checked) { 118 this.checked = checked; 119 } 120 121 /** 122 * Returns true if checked, false if not checked. 123 * @return true if checked 124 */ 125 public boolean isChecked() { 126 return checked; 127 } 128 129 /** 130 * Gets the Message that represents the rich message content of the label if labelText is using rich message tags. 131 * <b>DO NOT set this 132 * property directly unless you need full control over the message structure.</b> 133 * 134 * @return Message with rich message structure, null if no rich message structure 135 */ 136 @BeanTagAttribute 137 public Message getRichLabelMessage() { 138 return richLabelMessage; 139 } 140 141 /** 142 * Sets the Message that represents the rich message content of the label if it is using rich message tags. <b>DO 143 * NOT set this 144 * property directly unless you need full control over the message structure.</b> 145 * 146 * @param richLabelMessage 147 */ 148 public void setRichLabelMessage(Message richLabelMessage) { 149 this.richLabelMessage = richLabelMessage; 150 } 151 152 /** 153 * Gets the inlineComponents used by index in the checkboxLabel that has rich message component index tags 154 * 155 * @return the Label's inlineComponents 156 */ 157 @BeanTagAttribute 158 public List<Component> getInlineComponents() { 159 return inlineComponents; 160 } 161 162 /** 163 * Sets the inlineComponents used by index in the checkboxLabel that has rich message component index tags 164 * 165 * @param inlineComponents 166 */ 167 public void setInlineComponents(List<Component> inlineComponents) { 168 this.inlineComponents = inlineComponents; 169 } 170 171 /** 172 * {@inheritDoc} 173 */ 174 @Override 175 public void completeValidation(ValidationTrace tracer){ 176 tracer.addBean(this); 177 178 super.completeValidation(tracer.getCopy()); 179 } 180}