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.web.bind;
17  
18  import org.kuali.rice.core.api.util.type.AbstractKualiDecimal;
19  import org.kuali.rice.core.api.util.type.KualiDecimal;
20  import org.kuali.rice.core.api.util.type.KualiInteger;
21  import org.kuali.rice.core.api.util.type.KualiPercent;
22  import org.springframework.beans.propertyeditors.CustomNumberEditor;
23  import org.springframework.beans.propertyeditors.StringArrayPropertyEditor;
24  import org.springframework.beans.propertyeditors.StringTrimmerEditor;
25  import org.springframework.web.bind.WebDataBinder;
26  import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
27  import org.springframework.web.context.request.WebRequest;
28  import org.springframework.web.multipart.support.ByteArrayMultipartFileEditor;
29  
30  import java.math.BigDecimal;
31  import java.sql.Timestamp;
32  import java.text.DecimalFormat;
33  
34  /**
35   * Registers standard PropertyEditors used in binding for all http requests.
36   *
37   * @author Kuali Rice Team (rice.collab@kuali.org)
38   */
39  public class UifConfigurableWebBindingInitializer extends ConfigurableWebBindingInitializer {
40  
41      @Override
42      public void initBinder(WebDataBinder binder, WebRequest request) {
43          super.initBinder(binder, request);
44  
45          binder.registerCustomEditor(KualiDecimal.class, new UifCurrencyEditor());
46          binder.registerCustomEditor(KualiInteger.class, new UifKualiIntegerCurrencyEditor());
47  
48          binder.registerCustomEditor(KualiPercent.class, new UifPercentageEditor());
49  
50          binder.registerCustomEditor(java.sql.Date.class, new UifDateEditor());
51          binder.registerCustomEditor(java.util.Date.class, new UifDateEditor());
52          binder.registerCustomEditor(Timestamp.class, new UifTimestampEditor());
53  
54          // TODO do we need this since we are switching to spring tags
55          binder.registerCustomEditor(boolean.class, new UifBooleanEditor());
56          binder.registerCustomEditor(Boolean.class, new UifBooleanEditor());
57          binder.registerCustomEditor(Boolean.TYPE, new UifBooleanEditor());
58  
59          // Use the spring custom number editor for Big decimals
60          DecimalFormat bigIntFormatter = new DecimalFormat();
61          bigIntFormatter.setMaximumFractionDigits(340);
62          binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, bigIntFormatter, true));
63          binder.registerCustomEditor(AbstractKualiDecimal.class, new CustomNumberEditor(AbstractKualiDecimal.class,
64                  bigIntFormatter, true));
65  
66          // Use the spring StringTrimmerEditor editor for Strings
67          binder.registerCustomEditor(String.class, new StringTrimmerEditor(false));
68  
69          // Use the StringArrayPropertyEditor for string arrays with "," as the
70          // separator
71          binder.registerCustomEditor(String[].class, new StringArrayPropertyEditor(",", false));
72  
73          binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
74      }
75  }