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