1 16 17 package org.springframework.validation; 18 19 import java.util.Map ; 20 21 import org.springframework.util.Assert; 22 23 30 public abstract class BindingResultUtils { 31 32 39 public static BindingResult getBindingResult(Map model, String name) { 40 Assert.notNull(model, "Model map must not be null"); 41 Assert.notNull(name, "Name must not be null"); 42 Object attr = model.get(BindingResult.MODEL_KEY_PREFIX + name); 43 if (attr != null && !(attr instanceof BindingResult)) { 44 throw new IllegalStateException ("BindingResult attribute is not of type BindingResult: " + attr); 45 } 46 return (BindingResult) attr; 47 } 48 49 56 public static BindingResult getRequiredBindingResult(Map model, String name) { 57 BindingResult bindingResult = getBindingResult(model, name); 58 if (bindingResult == null) { 59 throw new IllegalStateException ("No BindingResult attribute found for name '" + name + 60 "'- have you exposed the correct model?"); 61 } 62 return bindingResult; 63 } 64 65 } 66 | Popular Tags |