• Post Reply Bookmark Topic Watch Topic
  • New Topic

Edit/New Pages best practice

 
Kalichar Rangantittu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an application that does a create and edit of a Business object using JSPs. What is the best practice, separate the content into two separate JSPs, or one single JSP assuming the forms to be submitted are identical?

With separate JSPs, on the create, I would not need to check whether the object to fill out the text fields and selected combo boxes etc is existent in the scope?

For example, on an edit, I do the following:

request.setAttribute("user", userObject);

then in the page, I would use JSTL to display the contents. However, on a new, the user object would not be in the request scope, so in the JSP I would need to keep checking if the user exists or not.

Thanks.
 
Stefan Evans
Bartender
Posts: 1822
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I prefer the approach of using a shared view (JSP) for all CRUD operations.
So that is on single JSP for both creating new records, and editing them (assuming they have exactly the same info)
Rather than checking for an existing user object all the time, I create a "dummy" object and populate it with default values.
That way it is treated exactly the same as an edit in terms of populating the screen.

In fact, rather than treating create and update as two different operations, sometimes I just create a generic "save". All my objects have an Id. If the Id is null, I know it is a new record, and can call the appropriate sql.



Note that the ? match the same fields in both insert and update statements, so you can use shared code from this point on where prepared statements.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stefan Evans:
Rather than checking for an existing user object all the time, I create a "dummy" object and populate it with default values.
That way it is treated exactly the same as an edit in terms of populating the screen.


Ditto.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!