Receiving an array of Object from a web form using Spring framework

Receiving an array of Object from a web form using Spring framework

I have a form JSP web page, this form contains multiple instances of the same Java object, I am using Java Spring Framework to control the "communication" with the controller and the view.

My problem is that i would like to be able to receive from the view a simple array containing the instances of my objects wich are currently on the page (on wich were probably modified).

When i want a specific kind of item, I usually just name it in my controller's method declaration, however for an array (or any Collection), this won't work.

so something like:

@RequestMapping public String edit(...SomeObject[] objectName, ...){ } 

would just return me an error, i can however receive an array of String, so this works:

@RequestMapping public String edit(...String[] objectString, ...){ } 

the goal would be to be able to make Spring automatically map the object thanks for your answers!

Spring context.xml and Set.contains()


How to use CurrentSessionContext/SpringSessionContext along with HibernateDaoSupport to intercept calls to getCurrentSession()
Spring does not know how to create your custom object from a String so you will need to create your own PropertyEditor for your custom object..
How do I force a spring container not to return a singleton instance of a bean?
Chapter 5 of the Spring Reference explains data binding and there is an example in Chapter 13 of how to register custom property editors in your controller..
Custom spring scopes?

How can I determine what roles are required to access a URL with Spring Security?

Pointcut not working with Spring AOP


Spring constructor params?
This is certainly possible; while I've not done it using @RequestMapping, I know that you can retrieve a collection it can be done with a "command" object (or @ModelAttribute).
Access Spring beans from a servlet in JBoss
Define a POJO with a collection attribute as your command.
public class FooCommand {     private List<String> myCollection;     // Getter & Setter } 
Then access it in your controller.
@RequestMapping(value = "/foo", method = RequestMethod.POST) public String processSubmit(@ModelAttribute("fooCommand") FooCommand fooCmd) {     // do stuff with fooCmd.getMyCollection()  } 
That make any sense?.

70 out of 100 based on 40 user ratings 790 reviews