001 /** 002 * Copyright 2005-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.krad.web.bind; 017 018 import org.kuali.rice.core.api.util.type.AbstractKualiDecimal; 019 import org.kuali.rice.core.api.util.type.KualiDecimal; 020 import org.kuali.rice.core.api.util.type.KualiInteger; 021 import org.kuali.rice.core.api.util.type.KualiPercent; 022 import org.springframework.beans.propertyeditors.CustomNumberEditor; 023 import org.springframework.beans.propertyeditors.StringArrayPropertyEditor; 024 import org.springframework.beans.propertyeditors.StringTrimmerEditor; 025 import org.springframework.web.bind.WebDataBinder; 026 import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; 027 import org.springframework.web.context.request.WebRequest; 028 029 import java.math.BigDecimal; 030 import java.sql.Timestamp; 031 import java.text.DecimalFormat; 032 033 /** 034 * Registers standard PropertyEditors used in binding for all http requests. 035 * 036 * @author Kuali Rice Team (rice.collab@kuali.org) 037 */ 038 public class UifConfigurableWebBindingInitializer extends ConfigurableWebBindingInitializer { 039 040 @Override 041 public void initBinder(WebDataBinder binder, WebRequest request) { 042 super.initBinder(binder, request); 043 044 binder.registerCustomEditor(KualiDecimal.class, new UifCurrencyEditor()); 045 binder.registerCustomEditor(KualiInteger.class, new UifKualiIntegerCurrencyEditor()); 046 047 binder.registerCustomEditor(KualiPercent.class, new UifPercentageEditor()); 048 049 binder.registerCustomEditor(java.sql.Date.class, new UifDateEditor()); 050 binder.registerCustomEditor(java.util.Date.class, new UifDateEditor()); 051 binder.registerCustomEditor(Timestamp.class, new UifTimestampEditor()); 052 053 // TODO do we need this since we are switching to spring tags 054 binder.registerCustomEditor(boolean.class, new UifBooleanEditor()); 055 binder.registerCustomEditor(Boolean.class, new UifBooleanEditor()); 056 binder.registerCustomEditor(Boolean.TYPE, new UifBooleanEditor()); 057 058 // Use the spring custom number editor for Big decimals 059 DecimalFormat bigIntFormatter = new DecimalFormat(); 060 bigIntFormatter.setMaximumFractionDigits(340); 061 binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, bigIntFormatter, true)); 062 binder.registerCustomEditor(AbstractKualiDecimal.class, new CustomNumberEditor(AbstractKualiDecimal.class, 063 bigIntFormatter, true)); 064 065 // Use the spring StringTrimmerEditor editor for Strings 066 binder.registerCustomEditor(String.class, new StringTrimmerEditor(false)); 067 068 // Use the StringArrayPropertyEditor for string arrays with "," as the 069 // separator 070 binder.registerCustomEditor(String[].class, new StringArrayPropertyEditor(",", false)); 071 } 072 }