Spring Framework WebDataBinder - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework WebDataBinder class.

This code example shows how to use the following methods:setAllowedFields, setDisallowedFields, setRequiredFields
            super(); 
        } 
 
        @InitBinder 
        public void initBinderFirstParam(WebDataBinder dataBinder) {
            dataBinder.setAllowedFields("allowed1", "allowed2");
            dataBinder.setRequiredFields("required1", "required2");
            dataBinder.setDisallowedFields("disAllowed1", "disAllowed2");
        } 
 
        @InitBinder 
        public void initBinderSecondParam(WebRequest wr, WebDataBinder dataBinder) {
            dataBinder.setAllowedFields("allowed1", "allowed2");
        } 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getBindingResult, bind, getBindingResult, getTarget, getValidator
     * @param request   The http servlet request object. 
     * @param formObject    A form object. 
     * @return  A binding result containing the outcome of binding and validation. 
     */ 
    protected BindingResult bindAndValidate(HttpServletRequest request, Object formObject) {
        WebDataBinder binder = new WebDataBinder(formObject);
        binder.setValidator(validator);
        binder.bind(new MutablePropertyValues(request.getParameterMap()));
        binder.getValidator().validate(binder.getTarget(), binder.getBindingResult());
        return binder.getBindingResult();
    } 
 
    /** 
     * Creates an expected redirect view path. 
     * @param path  The path to the requested view. 
     * @return  The expected redirect view path. 
     */ 
    protected String createExpectedRedirectViewPath(String path) {
        StringBuilder builder = new StringBuilder();
        builder.append(VIEW_REDIRECT_PREFIX);
6
CodeRank
This code example shows how to use the following methods:
	private NativeWebRequest webRequest; 
 
	@Before 
	public void setUp() throws Exception { 
		paramErrors = new MethodParameter(getClass().getDeclaredMethod("handle", Errors.class), 0); 
		bindingResult = new WebDataBinder(new Object(), "attr").getBindingResult(); 
		webRequest = new ServletWebRequest(new MockHttpServletRequest()); 
	} 
 
	@Test 
	public void supports() throws Exception { 
		resolver.supportsParameter(paramErrors); 
	} 
 
	@Test 
	public void bindingResult() throws Exception { 
		ModelAndViewContainer mavContainer = new ModelAndViewContainer(); 
		mavContainer.addAttribute("ignore1", "value1"); 
		mavContainer.addAttribute("ignore2", "value2"); 
		mavContainer.addAttribute("ignore3", "value3"); 
6
CodeRank
This code example shows how to use the following methods:
	 * @param target the target object to bind onto (or {@code null} 
	 * if the binder is just used to convert a plain parameter value) 
	 * @see #DEFAULT_OBJECT_NAME 
	 */ 
	public PortletRequestDataBinder(Object target) {
		super(target);
	} 
 
	/** 
	 * Create a new PortletRequestDataBinder instance. 
	 * @param target the target object to bind onto (or {@code null} 
	 * if the binder is just used to convert a plain parameter value) 
	 * @param objectName the name of the target object 
	 */ 
	public PortletRequestDataBinder(Object target, String objectName) {
		super(target, objectName);
	} 
 
 
	/** 
6
CodeRank
This code example shows how to use the following methods:setBindingErrorProcessor, setValidator
    } 
 
    @InitBinder 
    protected void initBinder(WebDataBinder binder) {
        LazyBindingErrorProcessor errorProcessor = new LazyBindingErrorProcessor();
        binder.setValidator(new SavingsProductFormValidator(errorProcessor,configurationServiceFacade));
        binder.setBindingErrorProcessor(errorProcessor);
    } 
 
    @RequestMapping(method = RequestMethod.POST)
    public ModelAndView processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String cancel,
                                    @ModelAttribute("savingsProduct") @Valid SavingsProductFormBean savingsProductFormBean, BindingResult result, SessionStatus status) {
    	ModelAndView modelAndView = new ModelAndView("redirect:/previewSavingsProducts.ftl?editFormview=defineSavingsProduct");
    	configurationDto = this.configurationServiceFacade.getAccountingConfiguration();
    	modelAndView.addObject("GLCodeMode", configurationDto.getGlCodeMode());
        if (StringUtils.isNotBlank(cancel)) {
        	modelAndView.setViewName(REDIRECT_TO_ADMIN_SCREEN);
        	status.setComplete();
        } else if (result.hasErrors()) {
        	modelAndView.setViewName("defineSavingsProduct");
6
CodeRank
This code example shows how to use the following methods:setBindingErrorProcessor, setValidator
    } 
 
    @InitBinder 
    protected void initBinder(WebDataBinder binder) { 
        LazyBindingErrorProcessor errorProcessor = new LazyBindingErrorProcessor(); 
        binder.setValidator(new ChangePasswordValidator()); 
        binder.setBindingErrorProcessor(errorProcessor); 
    } 
     
    @RequestMapping(method = RequestMethod.POST) 
    public String processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String cancel, 
                                    @ModelAttribute("formBean") @Valid ChangePasswordFormBean formBean, 
                                    BindingResult result, 
                                    SessionStatus status, HttpServletRequest request) { 
 
        String viewName = HOME_PAGE; 
 
        if (CANCEL_PARAM_VALUE.equals(cancel)) { 
            viewName = REDIRECT_AND_LOGOUT; 
            status.setComplete(); 
6
CodeRank
This code example shows how to use the following methods:registerCustomEditor, setRequiredFields
     * property editors to be used for display and binding of custom types 
     * @param binder the data binder to configure 
     */ 
	@InitBinder 
    public void initBinder(WebDataBinder binder) {
		binder.setRequiredFields(new String[] { "creditCardNumber", "amount", "merchantNumber" });
		binder.registerCustomEditor(MonetaryAmount.class, new MonetaryAmountEditor());
		binder.registerCustomEditor(SimpleDate.class, new SimpleDateEditor());
    }	 
	 
	/** 
	 * Prepares the "new reward" form for display before it is rendered, then 
	 * selects it for display. Preparation logic consists of registering a 
	 * custom property editor to properly format initial form field values. 
	 * @return a selection of the "new reward" view with the data needed to 
	 * render it 
	 */ 
	@RequestMapping(value="/reward/new", method = RequestMethod.GET)
	public ModelAndView newForm() {
		RewardForm rewardForm = new RewardForm();
6
CodeRank
This code example shows how to use the following methods:getBindingResult, bind, getBindingResult, getTarget, getValidator
        verify(messageSourceMock, times(1)).getMessage(eq(messageCode), any(Object[].class), any(Locale.class)); 
        verifyNoMoreInteractions(messageSourceMock); 
    } 
 
    private BindingResult bindAndValidate(HttpServletRequest request, Object formObject) { 
        WebDataBinder binder = new WebDataBinder(formObject); 
        binder.setValidator(validator); 
        binder.bind(new MutablePropertyValues(request.getParameterMap())); 
        binder.getValidator().validate(binder.getTarget(), binder.getBindingResult()); 
        return binder.getBindingResult(); 
    } 
 
    private void initMessageSourceForFeedbackMessage(String feedbackMessageCode) { 
        when(messageSourceMock.getMessage(eq(feedbackMessageCode), any(Object[].class), any(Locale.class))).thenReturn(FEEDBACK_MESSAGE); 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:registerCustomEditor
     * 
     * @param binder Binder object to be injected 
     */ 
    @InitBinder 
    public void initBinder(WebDataBinder binder) { 
        binder.registerCustomEditor(String.class, "userSecurityDto.currentUserPassword", new DefaultStringEditor(true)); 
        binder.registerCustomEditor(String.class, "userSecurityDto.newUserPassword", new DefaultStringEditor(true)); 
        binder.registerCustomEditor(String.class, "userSecurityDto.newUserPasswordConfirm", 
                new DefaultStringEditor(true)); 
        binder.registerCustomEditor(Integer.class, "userProfileDto.pageSize", new PageSizeEditor()); 
        binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); 
        binder.registerCustomEditor(String.class, "avatar", new DefaultAvatarEditor(imageService)); 
    } 
 
    /** 
     * @param userService       to get current user and user by id 
     * @param breadcrumbBuilder the object which provides actions on {@link org.jtalks.jcommune.plugin.api.web.util.BreadcrumbBuilder} entity 
     * @param imageConverter    to prepare user avatar for view 
     * @param postService       to get all user's posts 
     * @param contactsService   for edit user contacts 
5
CodeRank
This code example shows how to use the following methods:setBindingErrorProcessor, setValidator
    } 
 
    @InitBinder 
    protected void initBinder(WebDataBinder binder) {
        LazyBindingErrorProcessor errorProcessor = new LazyBindingErrorProcessor();
        binder.setValidator(new SavingsProductFormValidator(errorProcessor, configurationServiceFacade));
        binder.setBindingErrorProcessor(errorProcessor);
    } 
 
    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView showPopulatedForm(@RequestParam(value = "productId", required = true) Integer productId) {
    	ModelAndView modelAndView = new ModelAndView("editSavingsProduct");
    	 
    	configurationDto = this.configurationServiceFacade.getAccountingConfiguration();
    	modelAndView.addObject("GLCodeMode", configurationDto.getGlCodeMode());
    	 
        SavingsProductFormDto referenceData = this.adminServiceFacade.retrieveSavingsProductFormReferenceData();
        SavingsProductDto savingsProductDto = adminServiceFacade.retrieveSavingsProductDetails(productId);
        SavingsProductFormBean savingsProductBean = new SavingsProductFormBeanAssembler().assembleReferenceData(referenceData);
         
5
CodeRank
See Code Examples for Spring Framework WebDataBinder Methods: