• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

same jsp page for add and edit  RSS feed

Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!