views:

43

answers:

2

I asked this question a few weeks ago and didn't get the answer I was looking for, so figured I'd ask again a little differently.

I need to construct a form in my UI which will allow users to view and edit complex, nested objects. If I were doing this the JSP way, I would use Spring's bind functionality to associate form fields with backing objects. Each field would be tagged with an "address" indicating which field in the back object it's associated. Is there an equivalent front-end technology which will allow me to associate form fields with nested objects? I'm imagining a syntax that would look something like this:

<input class="boundInput boundTo:mailingAddresses[0].street" type="text" value=""/>

And an acommpanying javascript function which would examine all of the "boundInput" fields on the page and attach listeners which would update a backing js object intelligently based on the boundTo: class.

Does anything like this exist? Does anyone agree that it would be nice to have?

Here's the question I asked before:

http://stackoverflow.com/questions/2308857/best-way-to-link-ui-elements-with-backing-javascript-objects

A: 

As per my knowledge there is no such plugin or similar available. I think if I can give you a brief idea about how this binding works, you may see things in a different view and you may need to redesign your application accordingly.

  • Spring has special tag libraries to work with this form bindings. So when designing the forms in your jsp, you have to use these taglibs to code your form.
  • When you add an object with a specific key in the modal and then use the same key in your form tag as modalAttribute, spring looks up the object with the key and then for every attribute you access inside that form, it will use it to lookup and set the value to the control. Seriously there is very little magic in here.
  • When you are posting data to the form, spring does a little magic by looking at the RequestParam Annotation and then tries to bind all possible attributes to that object based on OGNL paths.

So what you are asking may not be available is my guess. I am working in spring and MVC for more than 4 years and never needed such a thing. If you can elaborate your problem I can help you more...

Teja Kantamneni
I'm not talking about a hypothetical Spring feature, I'm talking about something that would work entirely on the front end, but in a way similar to Spring's binding functionality.
morgancodes
+1  A: 

I don't know about a library, but there's always this, assuming you're dealing with a global:

<input onchange="mailingAddresses[0].street=this.value" type="text" value=""/>

If not a global, there's DOM ways around that

Bob
Hmmm. I hadn't even considered that because i've been out of the habit of inline event handlers for so long. That might work though.
morgancodes