Example usage for org.springframework.web.bind ServletRequestDataBinder bind

List of usage examples for org.springframework.web.bind ServletRequestDataBinder bind

Introduction

In this page you can find the example usage for org.springframework.web.bind ServletRequestDataBinder bind.

Prototype

public void bind(ServletRequest request) 

Source Link

Document

Bind the parameters of the given request to this binder's target, also binding multipart files in case of a multipart request.

Usage

From source file:common.bind.ABindValidator.java

public BindingResult bindAndValidate(Object command, HttpServletRequest request) {
    ServletRequestDataBinder binder = new ServletRequestDataBinder(command);

    initBinder(binder);//from  w  w  w  . j ava 2 s.c om
    binder.bind(request);
    BindingResult res = binder.getBindingResult();
    validate(command, res, request);
    return res;
}

From source file:teste.framework.Action.java

public void bind(HttpServletRequest request, Object entity) {
    ServletRequestDataBinder db = new ServletRequestDataBinder(entity);
    db.registerCustomEditor(Calendar.class, new CalendarPropertyEditor("yyyy-MM-dd"));
    db.bind(request);
}

From source file:gallery.web.controller.pages.types.WallpaperRateType.java

@Override
public UrlBean execute(HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
        throws Exception {
    /** bind command */
    WallpaperRating command = new WallpaperRating();
    ServletRequestDataBinder binder = new ServletRequestDataBinder(command);
    binder.setRequiredFields(REQUIRED_FIELDS);

    binder.bind(request);
    BindingResult res = binder.getBindingResult();

    int error = '1';
    if (res.hasErrors()) {
        common.CommonAttributes.addErrorMessage("form_errors", request);
    } else {//  ww w  . j  av a2 s. c o  m
        //correcting rating
        gallery.web.support.wallpaper.rating.Utils.correctRate(command);

        command.setIp(request.getRemoteAddr());
        if (wallpaperService.getRowCount("id", command.getId_photo()) == 1) {
            Object[] values = new Object[] { command.getId_photo(), command.getIp() };
            if (wallpaperRatingService.getRowCount(RATE_WALLPAPER_WHERE, values) > 0) {
                common.CommonAttributes.addErrorMessage("duplicate_ip", request);
            } else {
                wallpaperRatingService.save(command);
                common.CommonAttributes.addHelpMessage("operation_succeed", request);
                error = '0';
            }
        } else {
            common.CommonAttributes.addErrorMessage("not_exists.wallpaper", request);
        }
    }
    OutputStream os = response.getOutputStream();
    os.write(error);
    os.flush();

    return null;
}

From source file:de.iew.web.isc.spring.IscRequestMethodArgumentResolver.java

public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer,
        NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory) throws Exception {
    DSRequest dsRequest = new DSRequest();
    WebDataBinder binder = webDataBinderFactory.createBinder(nativeWebRequest, dsRequest, "dsRequest");
    binder.setFieldMarkerPrefix("__");

    // Man kann noch eigene Property Editoren konfigurieren
    //binder.registerCustomEditor();

    if (binder instanceof ServletRequestDataBinder) {
        /*//from   w  w w .  j  a v  a2s.  c o m
        @TODO
                
        Wir machen es uns etwas leicht. Unser DSRequest Objekt muss
        eigentlich nur die isc_-Eigenschaften kennen. Dort ist auch isc_metaDataPreifx
        konfiguriert. Anhand dieses Prefix mssen wir die anderen Eiegenschaften auflsen.
         */
        ServletRequestDataBinder servletRequestDataBinder = (ServletRequestDataBinder) binder;
        HttpServletRequest request = (HttpServletRequest) nativeWebRequest.getNativeRequest();

        servletRequestDataBinder.bind(request);

        BindingResult bindingResult = binder.getBindingResult();
        modelAndViewContainer.addAttribute(BindingResult.MODEL_KEY_PREFIX + "dsRequest", bindingResult);

        return dsRequest;
    } else {
        throw new UnsupportedOperationException(
                "Using " + binder.getClass() + " WebDataBinder is not supported.");
    }

}

From source file:org.sakaiproject.metaobj.utils.mvc.impl.servlet.ViewControllerImpl.java

protected ModelAndView handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
        Object command, BindException errors) throws Exception {

    Map request = HttpServletHelper.getInstance().createRequestMap(httpServletRequest);
    Map session = HttpServletHelper.getInstance().createSessionMap(httpServletRequest);
    Map application = HttpServletHelper.getInstance().createApplicationMap(httpServletRequest);

    if (controller instanceof CustomCommandController) {
        command = ((CustomCommandController) controller).formBackingObject(request, session, application);
    }/*from w w  w .  jav  a 2  s  .  co m*/

    if (command != null) {
        ServletRequestDataBinder binder = createBinder(httpServletRequest, command);
        binder.bind(httpServletRequest);
    }

    if (controller instanceof LoadObjectController) {
        command = ((LoadObjectController) controller).fillBackingObject(command, request, session, application);
    }

    ModelAndView returnedMv = controller.handleRequest(command, request, session, application, errors);

    if (returnedMv.getViewName() != null) {
        // should get from mappings
        String mappedView = (String) screenMappings.get(returnedMv.getViewName());

        if (mappedView == null) {
            mappedView = returnedMv.getViewName();
        }
        /*
         if (controller instanceof ContextAwareController){
            ((ContextAwareController) controller).addContexts(getHelpManager().getActiveContexts(session), returnedMv.getModel(), mappedView);
         } else {
            getHelpManager().addContexts(session, mappedView);
         }
         getControllerFilterManager().processFilters(request, session, application, returnedMv, mappedView);
         */

        returnedMv = new ModelAndView(mappedView, returnedMv.getModel());
    }

    HttpServletHelper.getInstance().reloadApplicationMap(httpServletRequest, application);
    HttpServletHelper.getInstance().reloadSessionMap(httpServletRequest, session);
    HttpServletHelper.getInstance().reloadRequestMap(httpServletRequest, request);

    return returnedMv;
}

From source file:gallery.web.controller.resolution.cms.ResolutionCmsDelegate.java

public ModelAndView doMultiUpdate(HttpServletRequest req, HttpServletResponse resp) {
    //logger.fine("do=multi update");
    String action = req.getParameter("action");
    if (action != null && action.equals("multiUpdate")) {
        ResolutionMulti command = new ResolutionMulti();
        BindingResult res = null;/*from   w w  w .jav  a2  s .  c  o m*/

        ServletRequestDataBinder binder = new ServletRequestDataBinder(command);
        binder.bind(req);
        res = binder.getBindingResult();
        if (res.hasErrors()) {
            common.CommonAttributes.addErrorMessage("form_errors", req);
            //logger.fine("hasErrors");
        } else {
            int rez = service.updateObjectArrayShortById(new String[] { "width", "height" }, command.getId(),
                    command.getWidth(), command.getHeight());
            if (rez > 0) {
                common.CommonAttributes.addHelpMessage("operation_succeed", req);
                //logger.fine("not hasErrors");
            } else {
                common.CommonAttributes.addErrorMessage("operation_fail", req);
                //logger.fine("hasErrors");
            }
        }
    }
    //after updating values shoving all pages(doView)
    return doView(req, resp);
}

From source file:gallery.web.controller.resolution.cms.ResolutionCmsDelegate.java

public ModelAndView doInsert(HttpServletRequest req, HttpServletResponse resp/*, Pages command*/) {
    Map<String, Object> m = getCommonModel(req);
    m.put(config.getContentUrlAttribute(), insert_url);
    m.put("editForm_topHeader", "");

    String action = req.getParameter(gallery.web.controller.Config.ACTION_PARAM_NAME);
    Resolution command = new Resolution();

    if (action != null && action.equals("insert")) {
        /** bind command */
        ServletRequestDataBinder binder = new ServletRequestDataBinder(command);
        binder.setRequiredFields(REQUIRED_FIELDS);
        binder.bind(req);
        BindingResult res = binder.getBindingResult();
        validator.validateCMS(command, res);
        if (res.hasErrors()) {
            m.put(res.MODEL_KEY_PREFIX + "command", res);
            m.put("command", command);
            common.CommonAttributes.addErrorMessage("form_errors", req);
        } else {/*from w  w w. j ava 2 s  . co  m*/
            service.save(command);
            m.put("command", command);
            common.CommonAttributes.addHelpMessage("operation_succeed", req);
        }
    } else {
        m.put("command", command);
    }

    return new ModelAndView(config.getTemplateUrl(), m);
}

From source file:org.stockwatcher.web.StockController.java

private StockCriteria getCriteria(HttpServletRequest request) {
    StockCriteria criteria = new StockCriteria();
    ServletRequestDataBinder binder = new ServletRequestDataBinder(criteria);
    binder.registerCustomEditor(Integer[].class, "industryIds", new StringArrayPropertyEditor());
    binder.bind(request);
    return criteria;
}

From source file:org.sakaiproject.metaobj.utils.mvc.impl.servlet.FormControllerImpl.java

protected Object formBackingObject(HttpServletRequest request) throws Exception {
    Map requestMap = HttpServletHelper.getInstance().createRequestMap(request);
    Map session = HttpServletHelper.getInstance().createSessionMap(request);
    Map application = HttpServletHelper.getInstance().createApplicationMap(request);

    Object lightObject = null;//  w w  w .ja  v  a  2  s  . com

    if (controller instanceof CustomCommandController) {
        lightObject = ((CustomCommandController) controller).formBackingObject(requestMap, session,
                application);
    } else {
        lightObject = super.formBackingObject(request);
    }

    Object returned = lightObject;

    if (controller instanceof LoadObjectController) {
        // need to bind variables to fill in lightweight object
        // then pass object to real control to fill in
        // this will get the info from the backing store
        ServletRequestDataBinder binder = createBinder(request, lightObject);
        binder.bind(request);

        returned = ((LoadObjectController) controller).fillBackingObject(lightObject, requestMap, session,
                application);
    }

    /*
    if (controller instanceof ContextAwareController){
    ((ContextAwareController) controller).addContexts(getHelpManager().getActiveContexts(session), requestMap, getFormView());
    } else {
    getHelpManager().addContexts(session, getFormView());
    }
      */
    //getControllerFilterManager().processFilters(requestMap, session, application, null, getFormView());

    HttpServletHelper.getInstance().reloadApplicationMap(request, application);
    HttpServletHelper.getInstance().reloadSessionMap(request, session);
    HttpServletHelper.getInstance().reloadRequestMap(request, requestMap);
    return returned;
}

From source file:com.hmsinc.epicenter.webapp.map.MapStylingController.java

/**
 * @param request//from  www .ja v a2s  .  c  o  m
 * @return
 * @throws ServletException
 * @throws IOException
 */
private StyleParameters parse(HttpServletRequest request) throws ServletException, IOException {

    final AnalysisParametersDTO queryParams = new AnalysisParametersDTO();

    final ServletRequestDataBinder binder = new ServletRequestDataBinder(queryParams);
    binder.registerCustomEditor(DateTime.class, new DateTimePropertyEditor());
    binder.registerCustomEditor(Properties.class, new EncodedPropertiesPropertyEditor());

    binder.bind(request);
    Validate.notNull(queryParams, "No parameters were specified");

    final AnalysisParameters params = convertParameters(queryParams);
    Validate.notNull(params);

    final StyleParameters styleParameters = new StyleParameters(request, params, queryParams, getPrincipal());
    logger.trace("Parameters: {}", styleParameters);

    return styleParameters;
}