Alex wrote: > I didn't find the solution for my problem : > I got an use case where I have to add new student. > I had a StudentActionForm who got simple data like > name, first name, birth date. > I had an attributs who correspond on a formation > selected by a new student. > The formations data displayed into my view came > from a database. > How can I do these 2 job : > -first load formations datas > -second add a new student from > the same view page ??
First, this isn't a trivial problem so it's no wonder you haven't run across a simple solution. You'll need to set Struts aside for a while and work on the underlying problem. How are you going to access your database? You're correct that putting SQL queries directly into your Action isn't a good idea. Personally, I implemented the entire Data Access Object pattern: http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.ht ml This may or may not be overkill for you. If the only "object" you need to read and write from your database is a single student with three fields, then you likely won't want to implement the entire thing. Instead you might want a single class: StudentDAO with create/read/update/delete methods. However you're doing the data access, you probably need "Data Transport Objects" (these used to be called "Value Objects"). Student (and StudentImpl if you go the interface route). (It will make your life easier if these conform to the JavaBeans property naming rules.) Get this all tested and working first, then bring Struts back into the picture. What you're describing is pretty similar to the example that ships with Struts, but you will have your own added complexities. In a nutshell, the user comes into the editStudent.do URL, the request gets handed to the EditStudentAction, and there you determine what's going on. Say he wants to load a student from the database. So you call studentDAO.read() and now you have a Student object. You move those values into the Form bean with BeanUtils.copyProperties() and then forward to the view. When he's done editing and wants to update, you move the values from the Form bean back to a Student object and call the studentDAO.update() method. For adding a student using the same page, you just skip the read() call and forward to the view with no values in the Form bean. Update works the same except that you have to deal with creating a new record in the database. Do take a look at the struts-example webapp. It has most of what you need once you deal with the database access part. Good luck! -- Wendy Smoak Applications Systems Analyst, Sr. Arizona State University PA Information Resources Management

