Announcement Announcement Module
Collapse
No announcement yet.
Building a property editor for a complex bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Building a property editor for a complex bean

    Hi,

    I just discover the principal of DataBinding through PropertyEditor in the Spring MVC.

    Basicly i have a simple object with 3 properties ( all strings ) : label, value and comment. This could be easily filled by the Spring MVC without even a dedicated CustomEditor.
    The trouble is that this object is part of object tree meaning that it has too more property : a reference to his father ( or mother) and a list of reference ( its children)... In my form i have a value that specify the node's deepness.

    I was going to follow this process to edit my bean :

    in my implementation of initBinder(), i'll will call a method that will extract ( ie remove ) the parameters regarding my bean from the request. I'll put them in my CustomEditor through the constructor. Then i'll register this new binder and go on with the binding. This way, in the CustomEditor i should have been able to edit the Bean with my own algorithm... The problem is : if i remove any trace of the data from the request, the CustomEditor will not be called. If I leave these datas, the binder will try to set the Bean and will fail to so correctly.

    The only solutions I see is to use a "buffer object" : a list of Bean unordered , but setted. From this bean I will be able to build the tree again. I'm not really found of this solution....

    Finally my question is more a request for advice : has anybody any idea on how to this correctly ? or at least in a "clean" way ?

  • #2
    Hi there,

    Perhaps one way of doing this would be to return the parameters you're interested under names not associated with the form object. This way they will be ignored by the standard binding mechanism.

    You can then override one of the doBind(...) methods and bind the parameters to your form object that way.

    Cheers

    Mike

    Comment

    Working...
    X