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.mock;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.uif.util.SessionTransient;
20  import org.kuali.rice.krad.web.form.UifFormBase;
21  import org.springframework.web.bind.annotation.RequestMethod;
22  
23  import javax.servlet.http.HttpServletRequest;
24  import java.util.Map;
25  
26  /**
27   * Form class for {@link org.kuali.rice.krad.uif.mock.MockView} instances that holds data in generic maps.
28   *
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   */
31  public class DynaForm extends UifFormBase {
32      private static final long serialVersionUID = -2112462466031059707L;
33  
34      private Map<String, Object> data;
35      private Map<String, Boolean> booleanData;
36  
37      @SessionTransient
38      private boolean initialGetRequest;
39  
40      /**
41       * Default constructor.
42       */
43      public DynaForm() {
44          super();
45      }
46  
47      /**
48       * {@inheritDoc}
49       */
50      @Override
51      public void postBind(HttpServletRequest request) {
52          // form key is assigned in super so need to do this check before it executes
53          if (StringUtils.isBlank(getFormKey()) && request.getMethod().equals(RequestMethod.GET.name())) {
54              initialGetRequest = true;
55          }
56  
57          super.postBind(request);
58      }
59  
60      /**
61       * Map containing non-boolean data for the view.
62       *
63       * @return map where key is property name and value is the property value
64       */
65      public Map<String, Object> getData() {
66          return data;
67      }
68  
69      /**
70       * @see DynaForm#getData()
71       */
72      public void setData(Map<String, Object> data) {
73          this.data = data;
74      }
75  
76      /**
77       * Map containing boolean data for the view.
78       *
79       * @return map where key is property name and value is the property value
80       */
81      public Map<String, Boolean> getBooleanData() {
82          return booleanData;
83      }
84  
85      /**
86       * @see DynaForm#getBooleanData()
87       */
88      public void setBooleanData(Map<String, Boolean> booleanData) {
89          this.booleanData = booleanData;
90      }
91  
92      /**
93       * Indicates whether the request is the initial get request for the view.
94       *
95       * @return boolean true if this is the initial request, false if not
96       */
97      public boolean isInitialGetRequest() {
98          return initialGetRequest;
99      }
100 }