Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Inserting a new record into a collection in a action form from a jsp

Thread view: 
simon_s_li@hotmail.com - 10 Oct 2007 23:04 GMT
I want to create a jsp page that will contain records of data of users
(first name, last name, email).

These records are from a collection I store in a Action Form and
passed tgo the JSP.

However I may need to be able to add a new user.

So if I have 10 user records displaying at first on a JSP, then I want
to add a new user making it 11 records.

What is the cleanest way to add a new record to the collection of
users in the Action Form from the JSP?

I don't want messy JavaScript/HTML coding if possible.

As a nice to have I may also want to add multiple records before
saving.

Any examples or ideas?

Thanks.
sengsational - 13 Oct 2007 23:48 GMT
On Oct 10, 6:04 pm, simon_s...@hotmail.com wrote:
> I want to create a jsp page that will contain records of data of users
> (first name, last name, email).
>
> These records are from a collection I store in a Action Form and
> passed tgo the JSP.

Not sure what you mean by "Action Form".  Typically you'd have a
servlet that has a database back-end for something like this.

> However I may need to be able to add a new user.
>
[quoted text clipped - 3 lines]
> What is the cleanest way to add a new record to the collection of
> users in the Action Form from the JSP?

The cleanest way to do this would be to use "EL" (expression
language).  You simply pass your collection to the page, and the
expression language would be able to pick it apart and display it.
For instance, you could define a "User" object with your 3 fields,
then make a collection with all of your existing users in it.  There's
a nice little package out there called "DisplayTag" which makes
displaying stuff like this very easy.

As for adding, you would make a form on the page with input fields.
Have the form submit to your servlet, which would validate the field
contents, and if it checks-out, create a new User object and add that
to your collection (i.e. myUserList.add(new User(first, last, id));)
You send your collection back to the page and if your page is set-up
right (with EL or DisplayTag) all users in the collection will
display.

> I don't want messy JavaScript/HTML coding if possible.
>
> As a nice to have I may also want to add multiple records before
> saving.

If what you mean by this is to not have a server round-trip for each
user, you could have "messy JavaScript" give the user more fields as
they are needed, or just give the user a fixed number of fields (i.e.
they could enter max 5 users at a time).

--Dale--


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.