View Javadoc
1   /**
2    * Copyright 2005-2015 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.web.bind;
17  
18  import org.kuali.rice.krad.web.form.UifFormBase;
19  import org.springframework.web.bind.ServletRequestDataBinder;
20  import org.springframework.web.bind.support.WebBindingInitializer;
21  import org.springframework.web.context.request.NativeWebRequest;
22  import org.springframework.web.method.support.InvocableHandlerMethod;
23  import org.springframework.web.servlet.mvc.method.annotation.ServletRequestDataBinderFactory;
24  
25  import java.util.List;
26  
27  /**
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   */
30  public class UifServletRequestDataBinderFactory extends ServletRequestDataBinderFactory {
31  
32      /**
33       * Create a new instance.
34       *
35       * @param binderMethods one or more {@code @InitBinder} methods
36       * @param initializer provides global data binder initialization
37       */
38      public UifServletRequestDataBinderFactory(List<InvocableHandlerMethod> binderMethods,
39              WebBindingInitializer initializer) {
40          super(binderMethods, initializer);
41      }
42  
43      @Override
44      protected ServletRequestDataBinder createBinderInstance(Object target, String objectName,
45              NativeWebRequest request) {
46          if (target != null) {
47              // only override for UifFormBase models so that non KRAD spring MVC
48              // can be used in same dispatcher servlet.
49              if (target instanceof UifFormBase) {
50                  return new UifServletRequestDataBinder(target, objectName);
51              }
52          }
53  
54          return super.createBinderInstance(target, objectName, request);
55      }
56  }