wood burning stoves 2.0*
The moose likes Struts and the fly likes same jsp page for add and edit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "same jsp page for add and edit" Watch "same jsp page for add and edit" New topic
Author

same jsp page for add and edit

zoheb siddiqui
Greenhorn

Joined: May 08, 2008
Posts: 11
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
Komal Renu
Ranch Hand

Joined: Jul 21, 2011
Posts: 51
Hi Zoheb,

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)
4. Now on click of submit button, invoke a javascript where you check the value of that hidden variable. If it is empty then invoke add function in action else invoke edit.
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.

Let me know if this helps.

Thanks and Regards,
-------------------------------------------------------------------------------------
Komal Renu | krenu@infocepts.com | www.infocepts.com
-------------------------------------------------------------------------------------
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: same jsp page for add and edit