1 /**
2 * Copyright 2005-2014 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.RiceKeyConstants;
19 import org.kuali.rice.core.web.format.FormatException;
20 import org.kuali.rice.krad.util.GlobalVariables;
21 import org.springframework.beans.PropertyAccessException;
22 import org.springframework.validation.BindingResult;
23 import org.springframework.validation.DefaultBindingErrorProcessor;
24
25 /**
26 * UIF handler for binding processing errors
27 *
28 * @author Kuali Rice Team (rice.collab@kuali.org)
29 */
30 public class UifBindingErrorProcessor extends DefaultBindingErrorProcessor {
31
32 /**
33 * Adds an entry to the {@link org.kuali.rice.krad.util.GlobalVariables#getMessageMap()} for the given
34 * binding processing error
35 *
36 * @param ex exception that was thrown
37 * @param bindingResult binding result containing the results of the binding process
38 */
39 @Override
40 public void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult) {
41 // Create field error with the exceptions's code, e.g. "typeMismatch".
42 super.processPropertyAccessException(ex, bindingResult);
43
44 Object rejectedValue = ex.getValue();
45 if (!(rejectedValue == null || rejectedValue.equals(""))) {
46 if (ex.getCause() instanceof FormatException) {
47 GlobalVariables.getMessageMap().putError(ex.getPropertyName(),
48 ((FormatException) ex.getCause()).getErrorKey(),
49 new String[] {rejectedValue.toString()});
50 } else {
51 GlobalVariables.getMessageMap().putError(ex.getPropertyName(), RiceKeyConstants.ERROR_CUSTOM,
52 new String[] {"Invalid format"});
53 }
54 }
55 }
56 }