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