private BinderConfiguration createBinderConfiguration(BinderModel binderModel) { if (binderModel != null && binderModel.getBindings() != null) { BinderConfiguration binderConfiguration = new BinderConfiguration(); List<BindingModel> bindings = binderModel.getBindings(); for (BindingModel bindingModel : bindings) { boolean required = false; if (StringUtils.hasText(bindingModel.getRequired())) { required = ((Boolean) fromStringTo(Boolean.class).execute(bindingModel.getRequired())); } Binding binding = new Binding(bindingModel.getProperty(), bindingModel.getConverter(), required); binderConfiguration.addBinding(binding); } return binderConfiguration; } else { return null; } }
/** * Gets the converterId for the binding with the specified name. Returns null if either a binding or a converterId * for the given name is not found. * * @param name the name of the binding. * @return the binding */ public String getConverterId(String name) { Binding binding = getBinding(name); if (binding != null) { return binding.getConverter(); } else { return null; } }
/** * <p> * Adds a {@link DefaultMapping} for every configured view {@link Binding} for which there is an incoming request * parameter. If there is no matching incoming request parameter, a special mapping is created that will set the * target field on the model to an empty value (typically null). * </p> * * @param mapper the mapper to which mappings will be added * @param parameterNames the request parameters * @param model the model */ protected void addModelBindings(DefaultMapper mapper, Set<String> parameterNames, Object model) { for (Binding binding : binderConfiguration.getBindings()) { String parameterName = binding.getProperty(); if (parameterNames.contains(parameterName)) { addMapping(mapper, binding, model); } else { if (fieldMarkerPrefix != null && parameterNames.contains(fieldMarkerPrefix + parameterName)) { addEmptyValueMapping(mapper, parameterName, model); } } } }
/** * 绑定输入信息 * * @param flow */ protected void bindCredential(Flow flow) { //重写绑定自定义credential createFlowVariable(flow, CasWebflowConstants.VAR_ID_CREDENTIAL, UsernamePasswordSysCredential.class); //登录页绑定新参数 final ViewState state = (ViewState) flow.getState(CasWebflowConstants.STATE_ID_VIEW_LOGIN_FORM); final BinderConfiguration cfg = getViewStateBinderConfiguration(state); //由于用户名以及密码已经绑定,所以只需对新加系统参数绑定即可 cfg.addBinding(new BinderConfiguration.Binding("system", null, false)); } }
private boolean isCustomConverterConfigured(String field) { if (binderConfiguration == null) { return false; } return (binderConfiguration.getConverterId(field) != null); }
/** * Create remember me authn webflow config. * * @param flow the flow */ protected void createRememberMeAuthnWebflowConfig(final Flow flow) { if (casProperties.getTicket().getTgt().getRememberMe().isEnabled()) { createFlowVariable(flow, CasWebflowConstants.VAR_ID_CREDENTIAL, RememberMeUsernamePasswordCredential.class); val state = getState(flow, CasWebflowConstants.STATE_ID_VIEW_LOGIN_FORM, ViewState.class); val cfg = getViewStateBinderConfiguration(state); cfg.addBinding(new BinderConfiguration.Binding("rememberMe", null, false)); } else { createFlowVariable(flow, CasWebflowConstants.VAR_ID_CREDENTIAL, UsernamePasswordCredential.class); } }
private PropertyEditor findSpringConvertingPropertyEditor(String field, Class<?> valueType) { if (conversionService != null) { String converterId = null; if (field != null) { if (binderConfiguration != null) { converterId = binderConfiguration.getConverterId(field); } if (valueType == null) { valueType = parseFieldExpression(field, false).getValueType(boundObject); } } if (valueType != null) { BeanWrapper accessor = PropertyAccessorFactory.forBeanPropertyAccess(boundObject); TypeDescriptor typeDescriptor = accessor.getPropertyTypeDescriptor(field); return new ConvertingPropertyEditorAdapter(conversionService, converterId, typeDescriptor); } else { return null; } } else { return null; } }
/** * Create state model bindings. * * @param properties the properties * @return the binder configuration */ public BinderConfiguration createStateBinderConfiguration(final List<String> properties) { val binder = new BinderConfiguration(); properties.forEach(p -> binder.addBinding(new BinderConfiguration.Binding(p, null, true))); return binder; }
/** * Gets the converterId for the binding with the specified name. Returns null if either a binding or a converterId * for the given name is not found. * * @param name the name of the binding. * @return the binding */ public String getConverterId(String name) { Binding binding = getBinding(name); if (binding != null) { return binding.getConverter(); } else { return null; } }
private void addModelBindings(DefaultMapper mapper, Set parameterNames, Object model) { Iterator it = binderConfiguration.getBindings().iterator(); while (it.hasNext()) { Binding binding = (Binding) it.next(); String parameterName = binding.getProperty(); if (parameterNames.contains(parameterName)) { addMapping(mapper, binding, model); } else { if (fieldMarkerPrefix != null && parameterNames.contains(fieldMarkerPrefix + parameterName)) { addEmptyValueMapping(mapper, parameterName, model); } } } }
private boolean isCustomConverterConfigured(String field) { if (binderConfiguration == null) { return false; } return (binderConfiguration.getConverterId(field) != null); }
private BinderConfiguration createBinderConfiguration(BinderModel binderModel) { if (binderModel != null && binderModel.getBindings() != null) { BinderConfiguration binderConfiguration = new BinderConfiguration(); List bindings = binderModel.getBindings(); for (Iterator it = bindings.iterator(); it.hasNext();) { BindingModel bindingModel = (BindingModel) it.next(); boolean required; if (StringUtils.hasText(bindingModel.getRequired())) { required = ((Boolean) fromStringTo(Boolean.class).execute(bindingModel.getRequired())) .booleanValue(); } else { required = false; } Binding binding = new Binding(bindingModel.getProperty(), bindingModel.getConverter(), required); binderConfiguration.addBinding(binding); } return binderConfiguration; } else { return null; } }
private ConversionExecutor getConverter(Expression fieldExpression) { if (conversionService != null) { Class valueType = fieldExpression.getValueType(boundObject); // special handling for array, collection, map types // necessary as getFieldValue is called by form tags for non-formattable properties, too // TODO - investigate how to improve this in Spring MVC if (valueType == null || valueType.isArray() || Collection.class.isAssignableFrom(valueType) || Map.class.isAssignableFrom(valueType)) { return null; } if (binderConfiguration != null) { Binding binding = binderConfiguration.getBinding(fieldExpression.getExpressionString()); if (binding != null) { String converterId = binding.getConverter(); if (converterId != null) { return conversionService.getConversionExecutor(converterId, valueType, String.class); } } } return conversionService.getConversionExecutor(valueType, String.class); } else { return null; } }
/** * <p> * Adds a {@link DefaultMapping} for every configured view {@link Binding} for which there is an incoming request * parameter. If there is no matching incoming request parameter, a special mapping is created that will set the * target field on the model to an empty value (typically null). * </p> * * @param mapper the mapper to which mappings will be added * @param parameterNames the request parameters * @param model the model */ protected void addModelBindings(DefaultMapper mapper, Set<String> parameterNames, Object model) { for (Binding binding : binderConfiguration.getBindings()) { String parameterName = binding.getProperty(); if (parameterNames.contains(parameterName)) { addMapping(mapper, binding, model); } else { if (fieldMarkerPrefix != null && parameterNames.contains(fieldMarkerPrefix + parameterName)) { addEmptyValueMapping(mapper, parameterName, model); } } } }
private PropertyEditor findSpringConvertingPropertyEditor(String field, Class<?> valueType) { if (conversionService != null) { String converterId = null; if (field != null) { if (binderConfiguration != null) { converterId = binderConfiguration.getConverterId(field); } if (valueType == null) { valueType = parseFieldExpression(field, false).getValueType(boundObject); } } if (valueType != null) { BeanWrapper accessor = PropertyAccessorFactory.forBeanPropertyAccess(boundObject); TypeDescriptor typeDescriptor = accessor.getPropertyTypeDescriptor(field); return new ConvertingPropertyEditorAdapter(conversionService, converterId, typeDescriptor); } else { return null; } } else { return null; } }
private BinderConfiguration createBinderConfiguration(BinderModel binderModel) { if (binderModel != null && binderModel.getBindings() != null) { BinderConfiguration binderConfiguration = new BinderConfiguration(); List<BindingModel> bindings = binderModel.getBindings(); for (BindingModel bindingModel : bindings) { boolean required = false; if (StringUtils.hasText(bindingModel.getRequired())) { required = ((Boolean) fromStringTo(Boolean.class).execute(bindingModel.getRequired())); } Binding binding = new Binding(bindingModel.getProperty(), bindingModel.getConverter(), required); binderConfiguration.addBinding(binding); } return binderConfiguration; } else { return null; } }
public void testGetFieldValueConvertedWithCustomConverter() { testBean.datum2 = 3; conversionService.addConverter("customConverter", new StringToObject(Integer.class) { protected Object toObject(String string, Class<?> targetClass) throws Exception { return Integer.valueOf(string); } protected String toString(Object object) throws Exception { return "$" + object; } }); BinderConfiguration binder = new BinderConfiguration(); binder.addBinding(new Binding("datum2", "customConverter", true)); model.setBinderConfiguration(binder); assertEquals("$3", model.getFieldValue("datum2")); }
conversionService.addConverter("customDateConverter", stringToDate); view.setConversionService(conversionService); BinderConfiguration binderConfiguration = new BinderConfiguration(); binderConfiguration.addBinding(new Binding("dateProperty", "customDateConverter", true)); view.setBinderConfiguration(binderConfiguration); view.processUserEvent();
AbstractMvcView view = new MockMvcView(mvcView, context); view.setExpressionParser(createExpressionParser()); BinderConfiguration binderConfiguration = new BinderConfiguration(); binderConfiguration.addBinding(new Binding("stringProperty", null, true)); view.setBinderConfiguration(binderConfiguration); view.processUserEvent();