View Javadoc
1   /**
2    * Copyright 2005-2014 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.finalize;
17  
18  import org.kuali.rice.krad.uif.field.DataField;
19  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
20  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleTaskBase;
21  import org.kuali.rice.krad.uif.lifecycle.ViewPostMetadata;
22  import org.kuali.rice.krad.uif.util.LifecycleElement;
23  
24  /**
25   * If the data field has a configured property editor registers the editor with the view
26   * post metadata.
27   *
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   * @see org.kuali.rice.krad.uif.field.DataField#getPropertyEditor()
30   */
31  public class RegisterPropertyEditorTask extends ViewLifecycleTaskBase<DataField> {
32  
33      /**
34       * Default constructor.
35       */
36      public RegisterPropertyEditorTask() {
37          super(DataField.class);
38      }
39  
40      /**
41       * {@inheritDoc}
42       */
43      @Override
44      protected void performLifecycleTask() {
45          LifecycleElement element = getElementState().getElement();
46  
47          if (!(element instanceof DataField)) {
48              return;
49          }
50  
51          DataField dataField = (DataField) element;
52  
53          if ((dataField.getPropertyEditor() == null) || !dataField.isRender()) {
54              return;
55          }
56  
57          ViewPostMetadata viewPostMetadata = ViewLifecycle.getViewPostMetadata();
58          if (dataField.hasSecureValue()) {
59              viewPostMetadata.addSecureFieldPropertyEditor(dataField.getBindingInfo().getBindingPath(),
60                      dataField.getPropertyEditor());
61          } else {
62              viewPostMetadata.addFieldPropertyEditor(dataField.getBindingInfo().getBindingPath(),
63                      dataField.getPropertyEditor());
64          }
65      }
66  }