Announcement Announcement Module
No announcement yet.
capture ServletRequestDataBinder Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • capture ServletRequestDataBinder

    Hello everyone!

    Firstly I am using "old" notation of Spring [with xml conf files] without annotations.

    I was reading workflow of AbstractFormController:

    and I am interesting to point number 10. The ServletRequestDataBinder gets applied to populate the form object with current request parameters.

    I really need to find a way to modify binder.

    Here is what I do:

    1. First Request and FormView
    2. Fullfilled inputs on my FormView (with Binding Errors, no ValidationErrors, for example captured by Spring)
    3. Submit (expect binding errors)
    4. AND HERE I NEED ACTUAL STATE OF COMMAND populated by ServletRequestDataBinder

    I am using dynamic list and when I invoke initBinder() or createBinder() on my point 4. I get "old" state of parameters.

    I need to disallowed some fileds after form invalidation, using servletRequestDataBinder.setDisallowedFields(disal lowedFields)

    Please, show me the way.
    Thanks !


    I have also tried with:

    protected void onBind(HttpServletRequest request, Object command,
    BindException errors) throws Exception {

    List<FieldError> removeList = new ArrayList<FieldError>();
    List<FieldError> lst = errors.getFieldErrors();
    for (FieldError fieldError : lst)

    super.onBind(request, command, errors);

    but Exception occurs
    java.util.Collections$UnmodifiableCollection.remov eAll(
    Last edited by fuss; Feb 23rd, 2010, 06:41 AM.

  • #2

    Here is what I did, and it solves my problem:

    protected ServletRequestDataBinder createBinder(HttpServletRequest request,
    Object command) throws Exception {

    ServletRequestDataBinder servletRequestDataBinder = super.createBinder(
    request, command);

    List<String> disallowedFields = new ArrayList<String>();

    if (isFormSubmission(request)) {

    MutablePropertyValues mpvs = new ServletRequestParameterPropertyValues(
    PropertyValue[] pvs = mpvs.getPropertyValues();

    String name = null;
    String value = null;

    for (PropertyValue pv : pvs) {
    name = PropertyAccessorUtils.canonicalPropertyName(pv
    value = (String) pv.getValue();

    //here we are info from submission
    servletRequestDataBinder.setDisallowedFields(disal lowedFields
    .toArray(new String[disallowedFields.size()]));


    return servletRequestDataBinder;