views:

240

answers:

2

I would like to create an object client side and add it to another object.

I'm using velocity and Spring.

I form a command object and pass it to the view as a backing object.

I want to create and add a new object to this command object without saving either object to the db.

The reason for this is that I want to have some persistence if there are errors during save. I want the command to be given back to the user in the same state it was submitted.

Thanks for the answers. Being more specific, I need to bind a number of fields to an object of an object.

For example if I wanted to create a new contact and add them to a customer acc. So the contact is made up of a number of strings. so I need to bind the strings to the contact and then bind the contact to a collection of contacts on the customer acc.

I'd like to do it in an expanding div so the user doesn't have to leave the page.

A: 

Check out the Spring Validation framework. It'll handle what you'd like to do.

duffymo
A: 

Support for this is built into the Spring Web MVC framework.

You need to implement a Validator for your command object and set this as the validator for your form controller. See Chapter 5 of the Spring reference for more details regarding validators.

Using the Spring velocity macros you bind your command object to the HTML form. The #springShowErrors macro is used to handle showing validiation errors.

Mark