i am new in struts 1.3 application development , i requirement is that what ever the forms i am developing i have to make 2 forms of same kind one for add purpose and another for edit purpose means i have a web form in that i have two fields one for entering the code and another for entering the name and a save button to save the data into database and when the user is in the add mode i display this from and in edit mode i display the other form which has got a hidden field ,one field for displaying the code and another is for displaying the name and the update button . through this he can update the data now my requirement is that can i use same form for adding and editing the information i have googled i found the that this can be done by using struts layout but not much information is available . if anybody can give me the some hint how to achieve this would be helpful for me
Joined: Jul 21, 2011
If i understand it correctly, you need to use a common jsp for Add and Edit, but don't know how to handle it with struts, right ?
I had a similar scenario in one of the applications that i worked on. Here's what i did.
1. Have the same form for the fields on the jsp.
2. Create the jsp and give all the fields there. Also give a hidden variable which is the id column in the database for your form details.
3. When you navigate to the form for add, that hidden variable wont have a value, whereas when you navigate for Edit, the Id will be set in it. (you need to handle this in your action class)
5. In you add/edit function you just need to set the user entered values in the pojo class for db table and invoke the saveOrUpdate() method of the persistence.