View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.uif.control;
17  
18  import java.util.List;
19  
20  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
21  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
22  import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
23  import org.kuali.rice.krad.uif.component.Component;
24  import org.kuali.rice.krad.uif.element.Message;
25  import org.kuali.rice.krad.uif.util.ComponentFactory;
26  import org.kuali.rice.krad.uif.util.ComponentUtils;
27  import org.kuali.rice.krad.uif.util.LifecycleElement;
28  
29  /**
30   * Represents a HTML Checkbox control. Typically used for boolean attributes (where the
31   * value is either on/off, true/false)
32   *
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   */
35  @BeanTag(name = "checkboxControl", parent = "Uif-CheckboxControl")
36  public class CheckboxControl extends ControlBase implements ValueConfiguredControl {
37      private static final long serialVersionUID = -1397028958569144230L;
38  
39      private String value;
40      private String checkboxLabel;
41      private boolean checked;
42  
43      private Message richLabelMessage;
44      private List<Component> inlineComponents;
45  
46      public CheckboxControl() {
47          super();
48      }
49  
50      /**
51       * Sets up rich message content for the label, if any exists
52       *
53       * {@inheritDoc}
54       */
55      @Override
56      public void performApplyModel(Object model, LifecycleElement parent) {
57          super.performApplyModel(model, parent);
58  
59          if (richLabelMessage == null) {
60              Message message = ComponentFactory.getMessage();
61              message.setMessageText(checkboxLabel);
62              message.setInlineComponents(inlineComponents);
63              message.setRenderWrapperTag(false);
64              this.setRichLabelMessage(message);
65          }
66      }
67  
68      /**
69       * The value that will be submitted when the checkbox control is checked
70       *
71       * <p>
72       * Value can be left blank, in which case the checkbox will submit a boolean value that
73       * will populate a boolean property. In cases where the checkbox needs to submit another value (for
74       * instance possibly in the checkbox group) the value can be set which will override the default.
75       * </p>
76       *
77       * @return value for checkbox
78       */
79      @BeanTagAttribute
80      public String getValue() {
81          return value;
82      }
83  
84      /**
85       * Setter for the value that should be submitted when the checkbox is checked
86       *
87       * @param value
88       */
89      public void setValue(String value) {
90          this.value = value;
91      }
92  
93      /**
94       * Returns the label text for this checkbox
95       *
96       * @return the checkbox label text
97       */
98      @BeanTagAttribute
99      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 }