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