View Javadoc
1   /**
2    * Copyright 2005-2016 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.lifecycle.model;
17  
18  import org.kuali.rice.krad.uif.component.Component;
19  import org.kuali.rice.krad.uif.field.DataField;
20  import org.kuali.rice.krad.uif.lifecycle.LifecycleElementState;
21  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
22  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleTaskBase;
23  import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
24  
25  /**
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   */
28  public class RefreshStateModifyTask extends ViewLifecycleTaskBase<Component> {
29  
30      /**
31       * Default constructor.
32       */
33      public RefreshStateModifyTask() {
34          super(Component.class);
35      }
36  
37      /**
38       * @see org.kuali.rice.krad.uif.lifecycle.ViewLifecycleTaskBase#performLifecycleTask()
39       */
40      @Override
41      protected void performLifecycleTask() {
42          LifecycleElementState phase = getElementState();
43          if (!ViewLifecycle.isRefreshComponent(phase.getViewPhase(), phase.getViewPath())) {
44              return;
45          }
46  
47          Component component = (Component) getElementState().getElement();
48  
49          // force the component to render on a refresh
50          component.setRender(true);
51  
52          // reset data if needed
53          if (component.isResetDataOnRefresh()) {
54              // TODO: this should handle groups as well, going through nested data fields
55              if (component instanceof DataField) {
56                  // TODO: should check default value
57  
58                  // clear value
59                  ObjectPropertyUtils.initializeProperty(ViewLifecycle.getModel(),
60                          ((DataField) component).getBindingInfo().getBindingPath());
61              }
62          }
63      }
64  
65  }