View Javadoc

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