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 java.util.ArrayList;
19  import java.util.List;
20  import java.util.Map;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
24  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
25  import org.kuali.rice.krad.datadictionary.parse.BeanTags;
26  import org.kuali.rice.krad.datadictionary.validator.ErrorReport;
27  import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
28  import org.kuali.rice.krad.datadictionary.validator.Validator;
29  import org.kuali.rice.krad.uif.component.Component;
30  import org.kuali.rice.krad.uif.element.Action;
31  import org.kuali.rice.krad.uif.element.Image;
32  
33  /**
34   * Field that encloses an @{link org.kuali.rice.krad.uif.element.Action} element
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  @BeanTags({@BeanTag(name = "actionField-bean", parent = "Uif-ActionField"),
39          @BeanTag(name = "actionLinkField-bean", parent = "Uif-ActionLinkField")})
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(Object model, Component parent) {
59          super.performFinalize(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#getAdditionalSubmitData()
191      */
192     @BeanTagAttribute(name = "additionalSubmitData", type = BeanTagAttribute.AttributeType.MAPVALUE)
193     public Map<String, String> getAdditionalSubmitData() {
194         return action.getAdditionalSubmitData();
195     }
196 
197     /**
198      * @see org.kuali.rice.krad.uif.element.Action#setAdditionalSubmitData(java.util.Map<java.lang.String,java.lang.String>)
199      */
200     public void setAdditionalSubmitData(Map<String, String> additionalSubmitData) {
201         action.setAdditionalSubmitData(additionalSubmitData);
202     }
203 
204     /**
205      * @see org.kuali.rice.krad.uif.element.Action#addActionParameter(java.lang.String, java.lang.String)
206      */
207     public void addActionParameter(String parameterName, String parameterValue) {
208         action.addActionParameter(parameterName, parameterValue);
209     }
210 
211     /**
212      * @see org.kuali.rice.krad.uif.element.Action#getActionParameter(java.lang.String)
213      */
214     public String getActionParameter(String parameterName) {
215         return action.getActionParameter(parameterName);
216     }
217 
218     /**
219      * @see org.kuali.rice.krad.uif.element.Action#getJumpToIdAfterSubmit()
220      */
221     @BeanTagAttribute(name = "jumpToIdAfterSubmit")
222     public String getJumpToIdAfterSubmit() {
223         return action.getJumpToIdAfterSubmit();
224     }
225 
226     /**
227      * @see org.kuali.rice.krad.uif.element.Action#setJumpToIdAfterSubmit(java.lang.String)
228      */
229 
230     public void setJumpToIdAfterSubmit(String jumpToIdAfterSubmit) {
231         action.setJumpToIdAfterSubmit(jumpToIdAfterSubmit);
232     }
233 
234     /**
235      * @see org.kuali.rice.krad.uif.element.Action#getJumpToNameAfterSubmit()
236      */
237     @BeanTagAttribute(name = "jumpToNameAfterSubmit")
238     public String getJumpToNameAfterSubmit() {
239         return action.getJumpToNameAfterSubmit();
240     }
241 
242     /**
243      * @see org.kuali.rice.krad.uif.element.Action#setJumpToNameAfterSubmit(java.lang.String)
244      */
245     public void setJumpToNameAfterSubmit(String jumpToNameAfterSubmit) {
246         action.setJumpToNameAfterSubmit(jumpToNameAfterSubmit);
247     }
248 
249     /**
250      * @see org.kuali.rice.krad.uif.element.Action#getFocusOnIdAfterSubmit()
251      */
252     @BeanTagAttribute(name = "focusOnIdAfterSubmit")
253     public String getFocusOnIdAfterSubmit() {
254         return action.getFocusOnIdAfterSubmit();
255     }
256 
257     /**
258      * @see org.kuali.rice.krad.uif.element.Action#setFocusOnIdAfterSubmit(java.lang.String)
259      */
260     public void setFocusOnIdAfterSubmit(String focusOnAfterSubmit) {
261         action.setFocusOnIdAfterSubmit(focusOnAfterSubmit);
262     }
263 
264     /**
265      * @see org.kuali.rice.krad.uif.element.Action#isPerformClientSideValidation()
266      */
267     @BeanTagAttribute(name = "performClientSideValidation")
268     public boolean isPerformClientSideValidation() {
269         return action.isPerformClientSideValidation();
270     }
271 
272     /**
273      * @see org.kuali.rice.krad.uif.element.Action#setPerformClientSideValidation(boolean)
274      */
275     public void setPerformClientSideValidation(boolean clientSideValidate) {
276         action.setPerformClientSideValidation(clientSideValidate);
277     }
278 
279     /**
280      * @see org.kuali.rice.krad.uif.element.Action#getActionScript()
281      */
282     @BeanTagAttribute(name = "actionScript")
283     public String getActionScript() {
284         return action.getActionScript();
285     }
286 
287     /**
288      * @see org.kuali.rice.krad.uif.element.Action#setActionScript(java.lang.String)
289      */
290     public void setActionScript(String actionScript) {
291         action.setActionScript(actionScript);
292     }
293 
294     /**
295      * @see org.kuali.rice.krad.uif.element.Action#isPerformDirtyValidation()
296      */
297     @BeanTagAttribute(name = "performDirtyValidation")
298     public boolean isPerformDirtyValidation() {
299         return action.isPerformDirtyValidation();
300     }
301 
302     /**
303      * @see org.kuali.rice.krad.uif.element.Action#setPerformDirtyValidation(boolean)
304      */
305     public void setPerformDirtyValidation(boolean blockValidateDirty) {
306         action.setPerformDirtyValidation(blockValidateDirty);
307     }
308 
309     /**
310      * @see org.kuali.rice.krad.uif.element.Action#isDisabled()
311      */
312     @BeanTagAttribute(name = "disabled")
313     public boolean isDisabled() {
314         return action.isDisabled();
315     }
316 
317     /**
318      * @see org.kuali.rice.krad.uif.element.Action#setDisabled(boolean)
319      */
320     public void setDisabled(boolean disabled) {
321         action.setDisabled(disabled);
322     }
323 
324     /**
325      * @see org.kuali.rice.krad.uif.element.Action#getDisabledReason()
326      */
327     @BeanTagAttribute(name = "disabledReason")
328     public String getDisabledReason() {
329         return action.getDisabledReason();
330     }
331 
332     /**
333      * @see org.kuali.rice.krad.uif.element.Action#setDisabledReason(java.lang.String)
334      */
335     public void setDisabledReason(String disabledReason) {
336         action.setDisabledReason(disabledReason);
337     }
338 
339     /**
340      * @see org.kuali.rice.krad.uif.element.Action#getActionImagePlacement()
341      */
342     @BeanTagAttribute(name = "actionImagePlacement")
343     public String getActionImagePlacement() {
344         return action.getActionImagePlacement();
345     }
346 
347     /**
348      * @see org.kuali.rice.krad.uif.element.Action#setActionImagePlacement(java.lang.String)
349      */
350     public void setActionImagePlacement(String actionImageLocation) {
351         action.setActionImagePlacement(actionImageLocation);
352     }
353 
354     /**
355      * @see org.kuali.rice.krad.uif.element.Action#getPreSubmitCall()
356      */
357     @BeanTagAttribute(name = "preSubmitCall")
358     public String getPreSubmitCall() {
359         return action.getPreSubmitCall();
360     }
361 
362     /**
363      * @see org.kuali.rice.krad.uif.element.Action#setPreSubmitCall(java.lang.String)
364      */
365     public void setPreSubmitCall(String preSubmitCall) {
366         action.setPreSubmitCall(preSubmitCall);
367     }
368 
369     /**
370      * @see org.kuali.rice.krad.uif.element.Action#isAjaxSubmit()
371      */
372     @BeanTagAttribute(name = "ajaxSubmit")
373     public boolean isAjaxSubmit() {
374         return action.isAjaxSubmit();
375     }
376 
377     /**
378      * @see org.kuali.rice.krad.uif.element.Action#setAjaxSubmit(boolean)
379      */
380     public void setAjaxSubmit(boolean ajaxSubmit) {
381         action.setAjaxSubmit(ajaxSubmit);
382     }
383 
384     /**
385      * @see org.kuali.rice.krad.uif.element.Action#getSuccessCallback()
386      */
387     @BeanTagAttribute(name = "successCallback")
388     public String getSuccessCallback() {
389         return action.getSuccessCallback();
390     }
391 
392     /**
393      * @param successCallback
394      * @see org.kuali.rice.krad.uif.element.Action#setSuccessCallback(java.lang.String)
395      */
396     public void setSuccessCallback(String successCallback) {
397         action.setSuccessCallback(successCallback);
398     }
399 
400     /**
401      * @see org.kuali.rice.krad.uif.element.Action#getErrorCallback()
402      */
403     @BeanTagAttribute(name = "errorCallback")
404     public String getErrorCallback() {
405         return action.getErrorCallback();
406     }
407 
408     /**
409      * @param errorCallback
410      * @see org.kuali.rice.krad.uif.element.Action#setErrorCallback(java.lang.String)
411      */
412     public void setErrorCallback(String errorCallback) {
413         action.setErrorCallback(errorCallback);
414     }
415 
416     /**
417      * @see org.kuali.rice.krad.uif.element.Action#getRefreshId()
418      */
419     @BeanTagAttribute(name = "refreshId")
420     public String getRefreshId() {
421         return action.getRefreshId();
422     }
423 
424     /**
425      * @see org.kuali.rice.krad.uif.element.Action#setRefreshId(java.lang.String)
426      */
427     public void setRefreshId(String refreshId) {
428         action.setRefreshId(refreshId);
429     }
430 
431     /**
432      * @see org.kuali.rice.krad.uif.element.Action#isDisableBlocking()
433      */
434     @BeanTagAttribute(name = "disableBlocking")
435     public boolean isDisableBlocking() {
436         return action.isDisableBlocking();
437     }
438 
439     /**
440      * @see org.kuali.rice.krad.uif.element.Action#setDisableBlocking(boolean)
441      */
442     public void setDisableBlocking(boolean disableBlocking) {
443         action.setDisableBlocking(disableBlocking);
444     }
445 
446     /**
447      * @see org.kuali.rice.krad.datadictionary.DictionaryBeanBase#copyProperties(Object)
448      */
449     @Override
450     protected <T> void copyProperties(T component) {
451         super.copyProperties(component);
452 
453         ActionField actionFieldCopy = (ActionField) component;
454 
455         if (this.action != null) {
456             actionFieldCopy.setAction((Action)this.action.copy());
457         }
458     }
459 
460     /**
461      * @see org.kuali.rice.krad.uif.component.Component#completeValidation
462      */
463     @Override
464     public void completeValidation(ValidationTrace tracer) {
465         ArrayList<ErrorReport> reports = new ArrayList<ErrorReport>();
466         tracer.addBean(this);
467 
468         // Checks that the action is set
469         if (getAction() == null) {
470             if (Validator.checkExpressions(this, "action")) {
471                 String currentValues[] = {"action =" + getAction()};
472                 tracer.createWarning("Action should not be null", currentValues);
473             }
474         }
475 
476         // checks that the label is set
477         if (getLabel() == null) {
478             if (Validator.checkExpressions(this, "label")) {
479                 String currentValues[] = {"label =" + getLabel(), "action =" + getAction()};
480                 tracer.createWarning("Label is null, action should be used instead", currentValues);
481             }
482         }
483 
484         super.completeValidation(tracer.getCopy());
485     }
486 }