View Javadoc

1   /**
2    * Copyright 2005-2013 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.field;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21  import org.kuali.rice.krad.datadictionary.validator.ErrorReport;
22  import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
23  import org.kuali.rice.krad.datadictionary.validator.Validator;
24  import org.kuali.rice.krad.uif.component.Component;
25  import org.kuali.rice.krad.uif.component.ComponentSecurity;
26  import org.kuali.rice.krad.uif.element.Action;
27  import org.kuali.rice.krad.uif.element.Image;
28  import org.kuali.rice.krad.uif.view.View;
29  
30  import java.util.ArrayList;
31  import java.util.List;
32  import java.util.Map;
33  
34  /**
35   * Field that encloses an @{link org.kuali.rice.krad.uif.element.Action} element
36   *
37   * @author Kuali Rice Team (rice.collab@kuali.org)
38   */
39  @BeanTag(name = "actionField-bean", parent = "Uif-ActionField")
40  public class ActionField extends FieldBase {
41      private static final long serialVersionUID = -8495752159848603102L;
42  
43      private Action action;
44  
45      public ActionField() {
46          action = new Action();
47      }
48  
49      /**
50       * PerformFinalize override - calls super, corrects the field's Label for attribute to point to this field's
51       * content
52       *
53       * @param view the view
54       * @param model the model
55       * @param parent the parent component
56       */
57      @Override
58      public void performFinalize(View view, Object model, Component parent) {
59          super.performFinalize(view, model, parent);
60  
61          //determine what id to use for the for attribute of the label, if present
62          if (this.getFieldLabel() != null && this.getAction() != null && StringUtils.isNotBlank(
63                  this.getAction().getId())) {
64              this.getFieldLabel().setLabelForComponentId(this.getAction().getId());
65          }
66      }
67  
68      /**
69       * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle()
70       */
71      @Override
72      public List<Component> getComponentsForLifecycle() {
73          List<Component> components = super.getComponentsForLifecycle();
74  
75          components.add(action);
76  
77          return components;
78      }
79  
80      /**
81       * Nested action component
82       *
83       * @return Action instance
84       */
85      @BeanTagAttribute(name = "action", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
86      public Action getAction() {
87          return action;
88      }
89  
90      /**
91       * Setter for the nested action component
92       *
93       * @param action
94       */
95      public void setAction(Action action) {
96          this.action = action;
97      }
98  
99      /**
100      * @see org.kuali.rice.krad.uif.element.Action#getMethodToCall()
101      */
102     @BeanTagAttribute(name = "methodToCall")
103     public String getMethodToCall() {
104         return action.getMethodToCall();
105     }
106 
107     /**
108      * @see org.kuali.rice.krad.uif.element.Action#setMethodToCall(java.lang.String)
109      */
110     public void setMethodToCall(String methodToCall) {
111         action.setMethodToCall(methodToCall);
112     }
113 
114     /**
115      * @see org.kuali.rice.krad.uif.element.Action#getActionLabel()
116      */
117     @BeanTagAttribute(name = "actionLabel")
118     public String getActionLabel() {
119         return action.getActionLabel();
120     }
121 
122     /**
123      * @see org.kuali.rice.krad.uif.element.Action#setActionLabel(java.lang.String)
124      */
125     public void setActionLabel(String actionLabel) {
126         action.setActionLabel(actionLabel);
127     }
128 
129     /**
130      * @see org.kuali.rice.krad.uif.element.Action#getActionImage()
131      */
132     @BeanTagAttribute(name = "actionImage", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
133     public Image getActionImage() {
134         return action.getActionImage();
135     }
136 
137     /**
138      * @see org.kuali.rice.krad.uif.element.Action#setActionImage(org.kuali.rice.krad.uif.element.Image)
139      */
140     public void setActionImage(Image actionImage) {
141         action.setActionImage(actionImage);
142     }
143 
144     /**
145      * @see org.kuali.rice.krad.uif.element.Action#getNavigateToPageId()
146      */
147     @BeanTagAttribute(name = "navigateToPageId")
148     public String getNavigateToPageId() {
149         return action.getNavigateToPageId();
150     }
151 
152     /**
153      * @see org.kuali.rice.krad.uif.element.Action#setNavigateToPageId(java.lang.String)
154      */
155     public void setNavigateToPageId(String navigateToPageId) {
156         action.setNavigateToPageId(navigateToPageId);
157     }
158 
159     /**
160      * @see org.kuali.rice.krad.uif.element.Action#getActionEvent()
161      */
162     @BeanTagAttribute(name = "actionEvent")
163     public String getActionEvent() {
164         return action.getActionEvent();
165     }
166 
167     /**
168      * @see org.kuali.rice.krad.uif.element.Action#setActionEvent(java.lang.String)
169      */
170     public void setActionEvent(String actionEvent) {
171         action.setActionEvent(actionEvent);
172     }
173 
174     /**
175      * @see org.kuali.rice.krad.uif.element.Action#getActionParameters()
176      */
177     @BeanTagAttribute(name = "actionParameters", type = BeanTagAttribute.AttributeType.MAPVALUE)
178     public Map<String, String> getActionParameters() {
179         return action.getActionParameters();
180     }
181 
182     /**
183      * @see org.kuali.rice.krad.uif.element.Action#setActionParameters(java.util.Map<java.lang.String,java.lang.String>)
184      */
185     public void setActionParameters(Map<String, String> actionParameters) {
186         action.setActionParameters(actionParameters);
187     }
188 
189     /**
190      * @see org.kuali.rice.krad.uif.element.Action#addActionParameter(java.lang.String, java.lang.String)
191      */
192     public void addActionParameter(String parameterName, String parameterValue) {
193         action.addActionParameter(parameterName, parameterValue);
194     }
195 
196     /**
197      * @see org.kuali.rice.krad.uif.element.Action#getActionParameter(java.lang.String)
198      */
199     public String getActionParameter(String parameterName) {
200         return action.getActionParameter(parameterName);
201     }
202 
203     /**
204      * @see org.kuali.rice.krad.uif.element.Action#setComponentSecurity(org.kuali.rice.krad.uif.component.ComponentSecurity)
205      */
206     public void setComponentSecurity(ComponentSecurity componentSecurity) {
207         action.setComponentSecurity(componentSecurity);
208     }
209 
210     /**
211      * @see org.kuali.rice.krad.uif.element.Action#getJumpToIdAfterSubmit()
212      */
213     @BeanTagAttribute(name = "jumpToIdAfterSubmit")
214     public String getJumpToIdAfterSubmit() {
215         return action.getJumpToIdAfterSubmit();
216     }
217 
218     /**
219      * @see org.kuali.rice.krad.uif.element.Action#setJumpToIdAfterSubmit(java.lang.String)
220      */
221 
222     public void setJumpToIdAfterSubmit(String jumpToIdAfterSubmit) {
223         action.setJumpToIdAfterSubmit(jumpToIdAfterSubmit);
224     }
225 
226     /**
227      * @see org.kuali.rice.krad.uif.element.Action#getJumpToNameAfterSubmit()
228      */
229     @BeanTagAttribute(name = "jumpToNameAfterSubmit")
230     public String getJumpToNameAfterSubmit() {
231         return action.getJumpToNameAfterSubmit();
232     }
233 
234     /**
235      * @see org.kuali.rice.krad.uif.element.Action#setJumpToNameAfterSubmit(java.lang.String)
236      */
237     public void setJumpToNameAfterSubmit(String jumpToNameAfterSubmit) {
238         action.setJumpToNameAfterSubmit(jumpToNameAfterSubmit);
239     }
240 
241     /**
242      * @see org.kuali.rice.krad.uif.element.Action#getFocusOnIdAfterSubmit()
243      */
244     @BeanTagAttribute(name = "focusOnIdAfterSubmit")
245     public String getFocusOnIdAfterSubmit() {
246         return action.getFocusOnIdAfterSubmit();
247     }
248 
249     /**
250      * @see org.kuali.rice.krad.uif.element.Action#setFocusOnIdAfterSubmit(java.lang.String)
251      */
252     public void setFocusOnIdAfterSubmit(String focusOnAfterSubmit) {
253         action.setFocusOnIdAfterSubmit(focusOnAfterSubmit);
254     }
255 
256     /**
257      * @see org.kuali.rice.krad.uif.element.Action#isPerformClientSideValidation()
258      */
259     @BeanTagAttribute(name = "performClientSideValidation")
260     public boolean isPerformClientSideValidation() {
261         return action.isPerformClientSideValidation();
262     }
263 
264     /**
265      * @see org.kuali.rice.krad.uif.element.Action#setPerformClientSideValidation(boolean)
266      */
267     public void setPerformClientSideValidation(boolean clientSideValidate) {
268         action.setPerformClientSideValidation(clientSideValidate);
269     }
270 
271     /**
272      * @see org.kuali.rice.krad.uif.element.Action#getActionScript()
273      */
274     @BeanTagAttribute(name = "actionScript")
275     public String getActionScript() {
276         return action.getActionScript();
277     }
278 
279     /**
280      * @see org.kuali.rice.krad.uif.element.Action#setActionScript(java.lang.String)
281      */
282     public void setActionScript(String actionScript) {
283         action.setActionScript(actionScript);
284     }
285 
286     /**
287      * @see org.kuali.rice.krad.uif.element.Action#isPerformDirtyValidation()
288      */
289     @BeanTagAttribute(name = "performDirtyValidation")
290     public boolean isPerformDirtyValidation() {
291         return action.isPerformDirtyValidation();
292     }
293 
294     /**
295      * @see org.kuali.rice.krad.uif.element.Action#setPerformDirtyValidation(boolean)
296      */
297     public void setPerformDirtyValidation(boolean blockValidateDirty) {
298         action.setPerformDirtyValidation(blockValidateDirty);
299     }
300 
301     /**
302      * @see org.kuali.rice.krad.uif.element.Action#isDisabled()
303      */
304     @BeanTagAttribute(name = "disabled")
305     public boolean isDisabled() {
306         return action.isDisabled();
307     }
308 
309     /**
310      * @see org.kuali.rice.krad.uif.element.Action#setDisabled(boolean)
311      */
312     public void setDisabled(boolean disabled) {
313         action.setDisabled(disabled);
314     }
315 
316     /**
317      * @see org.kuali.rice.krad.uif.element.Action#getDisabledReason()
318      */
319     @BeanTagAttribute(name = "disabledReason")
320     public String getDisabledReason() {
321         return action.getDisabledReason();
322     }
323 
324     /**
325      * @see org.kuali.rice.krad.uif.element.Action#setDisabledReason(java.lang.String)
326      */
327     public void setDisabledReason(String disabledReason) {
328         action.setDisabledReason(disabledReason);
329     }
330 
331     /**
332      * @see org.kuali.rice.krad.uif.element.Action#getActionImagePlacement()
333      */
334     @BeanTagAttribute(name = "actionImagePlacement")
335     public String getActionImagePlacement() {
336         return action.getActionImagePlacement();
337     }
338 
339     /**
340      * @see org.kuali.rice.krad.uif.element.Action#setActionImagePlacement(java.lang.String)
341      */
342     public void setActionImagePlacement(String actionImageLocation) {
343         action.setActionImagePlacement(actionImageLocation);
344     }
345 
346     /**
347      * @see org.kuali.rice.krad.uif.element.Action#getPreSubmitCall()
348      */
349     @BeanTagAttribute(name = "preSubmitCall")
350     public String getPreSubmitCall() {
351         return action.getPreSubmitCall();
352     }
353 
354     /**
355      * @see org.kuali.rice.krad.uif.element.Action#setPreSubmitCall(java.lang.String)
356      */
357     public void setPreSubmitCall(String preSubmitCall) {
358         action.setPreSubmitCall(preSubmitCall);
359     }
360 
361     /**
362      * @see org.kuali.rice.krad.uif.element.Action#isAjaxSubmit()
363      */
364     @BeanTagAttribute(name = "ajaxSubmit")
365     public boolean isAjaxSubmit() {
366         return action.isAjaxSubmit();
367     }
368 
369     /**
370      * @see org.kuali.rice.krad.uif.element.Action#setAjaxSubmit(boolean)
371      */
372     public void setAjaxSubmit(boolean ajaxSubmit) {
373         action.setAjaxSubmit(ajaxSubmit);
374     }
375 
376     /**
377      * @see org.kuali.rice.krad.uif.element.Action#getSuccessCallback()
378      */
379     @BeanTagAttribute(name = "successCallback")
380     public String getSuccessCallback() {
381         return action.getSuccessCallback();
382     }
383 
384     /**
385      * @param successCallback
386      * @see org.kuali.rice.krad.uif.element.Action#setSuccessCallback(java.lang.String)
387      */
388     public void setSuccessCallback(String successCallback) {
389         action.setSuccessCallback(successCallback);
390     }
391 
392     /**
393      * @see org.kuali.rice.krad.uif.element.Action#getErrorCallback()
394      */
395     @BeanTagAttribute(name = "errorCallback")
396     public String getErrorCallback() {
397         return action.getErrorCallback();
398     }
399 
400     /**
401      * @param errorCallback
402      * @see org.kuali.rice.krad.uif.element.Action#setErrorCallback(java.lang.String)
403      */
404 
405     public void setErrorCallback(String errorCallback) {
406         action.setErrorCallback(errorCallback);
407     }
408 
409     /**
410      * @see org.kuali.rice.krad.uif.component.Component#completeValidation
411      */
412     @Override
413     public void completeValidation(ValidationTrace tracer) {
414         ArrayList<ErrorReport> reports = new ArrayList<ErrorReport>();
415         tracer.addBean(this);
416 
417         // Checks that the action is set
418         if (getAction() == null) {
419             if (Validator.checkExpressions(this, "action")) {
420                 String currentValues[] = {"action =" + getAction()};
421                 tracer.createWarning("Action should not be null", currentValues);
422             }
423         }
424 
425         // checks that the label is set
426         if (getLabel() == null) {
427             if (Validator.checkExpressions(this, "label")) {
428                 String currentValues[] = {"label =" + getLabel(), "action =" + getAction()};
429                 tracer.createWarning("Label is null, action should be used instead", currentValues);
430             }
431         }
432 
433         super.completeValidation(tracer.getCopy());
434     }
435 }