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

  • Using ServletRequestDataBinder

    I tried to bind parameters in Httprequest to my own bean

    So in onBind of my SimpleFormController, I do following

    Object o = Class.forName(MyBean).newInstance();
    res.put(bn, o);
    MutablePropertyValues mpvs = new ServletRequestParameterPropertyValues(request);
    ServletRequestDataBinder binder = new ServletRequestDataBinder(o);


    the incoming parameter appear in the request as

    MyBean.field1=fieldvalue

    The result was that I never got any bound to MyBean.

    The cause was pd =null in getPropertyValue of BeanWrapperImpl

    PropertyDescriptor pd = getPropertyDescriptorInternal(tokens.actualName);
    if (pd == null || pd.getReadMethod() == null) {
    throw new NotReadablePropertyException(getRootClass(), this.nestedPath + propertyName);
    }

    Then, the "NotReadablePropertyException" was thrown

    I also tried to use DataBinder directly providing mpvs like this

    MutablePropertyValues mpvs = new ServletRequestParameterPropertyValues(request);
    DataBinder binder = new DataBinder(o);
    binder.bind(mpvs);

    and the result was similar.

    My goal was to bind the parameters to a given bean.

    Is this the right way?

    Thanks

  • #2
    Correction

    The bold code should be (the code I used to bind)

    Object o = Class.forName(MyBean).newInstance();
    ServletRequestDataBinder binder = new ServletRequestDataBinder(o);
    binder.bind(request);


    Sorry

    Comment


    • #3
      May be I don't quite understand the question, but I generally use Spring's built in bindging mechanism, so that I don't have to write the code. If you are either using spring bind tag or spring form tags (form tags has path attribute that does the binding for you) then you should not need to bind parameter yourself.

      But may be I'm not following your question properly

      Comment

      Working...
      X