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

S

simon_s_li

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.
 
S

sengsational

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.

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?

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--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top