Announcement Announcement Module
Collapse
No announcement yet.
capture ServletRequestDataBinder Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:

    http://static.springsource.org/sprin...ontroller.html

    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 typeMismatch.java.lang.Double 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 !

    Regards.

    I have also tried with:

    @Override
    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)
    {
    removeList.add(fieldError);
    }
    lst.removeAll(removeList);

    super.onBind(request, command, errors);

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

  • #2
    Solution

    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(
    request);
    PropertyValue[] pvs = mpvs.getPropertyValues();

    String name = null;
    String value = null;

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

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

    }

    return servletRequestDataBinder;
    }

    Comment

    Working...
    X