This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

AnnouncementAnnouncement Module

Collapse

No announcement yet.

setting an object as value of object attribute of a backing bean in a formPage Title Module

setting an object as value of object attribute of a backing bean in a form

Nov 26th, 2011, 01:53 PM

Hi, am new to the spring MVC.
in my application, am using Hibernate.
I have a form for submitting student 's information
The student information will have a department as attribute(of Department data type).

in this form, the department will be selected from a select option. the code for the form is shown below
commandName is "student"

This way you'll bind the department 2 times to the same column (department_id) making sure that just the department(s) id is enabled to insert or update information. Your drop down box will look like this:

Note that your question is fully covered in the this demo (use of unit and vatrate dropdowns) with the item view and data model object on github. (Sorry for all the german articles names in the SheptOrder demo [ those are from one of germans biggest grocery discounters])

Comment

I will write the code which I have followed prior to your reply. and tell me which one will be better.

I have added property dummy_dept_id for student class, and made this attribute as Transient.
in the form, the itemValue of the department is set to this student.dummy_dept_id;
in the server side, the controller will handover the student object to the StudentService class for making a proper student object.
the StudentService class will have a method makeUpStudent(Student std) that will set the department field of the recieved student object with the deprtament having id equal t that of std.dummy_dept_id.
this student object is return back to the controller and the controller will forward it to the studentDao for saving it.
please check the code below. you will get a clear cut idea;