View Javadoc

1   /*
2    * Copyright 2007 The Kuali Foundation Licensed under the Educational Community
3    * License, Version 1.0 (the "License"); you may not use this file except in
4    * compliance with the License. You may obtain a copy of the License at
5    * http://www.opensource.org/licenses/ecl1.php Unless required by applicable law
6    * or agreed to in writing, software distributed under the License is
7    * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8    * KIND, either express or implied. See the License for the specific language
9    * governing permissions and limitations under the License.
10   */
11  package org.kuali.rice.krad.web.bind;
12  
13  import org.kuali.rice.core.api.util.type.AbstractKualiDecimal;
14  import org.kuali.rice.core.api.util.type.KualiDecimal;
15  import org.kuali.rice.core.api.util.type.KualiInteger;
16  import org.kuali.rice.core.api.util.type.KualiPercent;
17  import org.springframework.beans.propertyeditors.CustomNumberEditor;
18  import org.springframework.beans.propertyeditors.StringArrayPropertyEditor;
19  import org.springframework.beans.propertyeditors.StringTrimmerEditor;
20  import org.springframework.web.bind.WebDataBinder;
21  import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
22  import org.springframework.web.context.request.WebRequest;
23  
24  import java.math.BigDecimal;
25  import java.sql.Timestamp;
26  import java.text.DecimalFormat;
27  
28  /**
29   * Registers standard PropertyEditors used in binding for all http requests.
30   *
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  public class UifConfigurableWebBindingInitializer extends ConfigurableWebBindingInitializer {
34  
35      @Override
36      public void initBinder(WebDataBinder binder, WebRequest request) {
37          binder.registerCustomEditor(KualiDecimal.class, new UifCurrencyEditor());
38          binder.registerCustomEditor(KualiInteger.class, new UifKualiIntegerCurrencyEditor());
39  
40          binder.registerCustomEditor(KualiPercent.class, new UifPercentageEditor());
41  
42          binder.registerCustomEditor(java.sql.Date.class, new UifDateEditor());
43          binder.registerCustomEditor(java.util.Date.class, new UifDateEditor());
44          binder.registerCustomEditor(Timestamp.class, new UifTimestampEditor());
45  
46          // TODO do we need this since we are switching to spring tags
47          binder.registerCustomEditor(boolean.class, new UifBooleanEditor());
48          binder.registerCustomEditor(Boolean.class, new UifBooleanEditor());
49          binder.registerCustomEditor(Boolean.TYPE, new UifBooleanEditor());
50  
51          // Use the spring custom number editor for Big decimals
52          DecimalFormat bigIntFormatter = new DecimalFormat();
53          bigIntFormatter.setMaximumFractionDigits(340);
54          binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, bigIntFormatter, true));
55          binder.registerCustomEditor(AbstractKualiDecimal.class,
56                  new CustomNumberEditor(AbstractKualiDecimal.class, bigIntFormatter, true));
57  
58          // Use the spring StringTrimmerEditor editor for Strings
59          binder.registerCustomEditor(String.class, new StringTrimmerEditor(false));
60          // Use the StringArrayPropertyEditor for string arrays with "," as the
61          // separator
62          binder.registerCustomEditor(String[].class, new StringArrayPropertyEditor(",", false));
63  
64          super.initBinder(binder, request);
65      }
66  }