JSP mapping an HTML control to a Java bean

C

ccjjharmon

Good afternoon all.

I am at a loss of trying to figure out how to cleanly map what a user
selects on a JSP-driven webpage to an Java object.

Let me get right into the details:

A servlet interfaces with the databases and gets two Collection objects
that I set as attributes with request scope. The servlet then
dispatches its related JSP to "show" the user a pulldown menu for each
of the Collections. I iterate thru the collections' objects via JSTL,
but my problem is when the user submits the form on the JSP (which
submits to a "controller" servlet), I am only sending just one piece of
the selected object from the collection.

Now I know I *can*:
change the collection to some sort of list that has key to lookup
objects (e.g. ArrayList with its index per object)
persist the collection into session scope,
use the object key as the pulldown menu's option values
and within the servlet/JSP (whatever's next according to the controller
servlet), get the object that is returned from the key found by
request.getParameter()

But is this the best method? I kind of feel dirty doing it, but don't
really know why.

Are there are any other ways??

Anyone done this and care to comment on advantages/disadvantages?
 
D

Danno

I use the id from if it is a persistable bean or the hashCode if it
isn't. Most of that stuff I don't deal with anymore since I use JSF.
 
C

ccjjharmon

I had heard only a little bit about JSF - but since I am fairly new at
Java technology (including JSP), I haven't yet taken a stab at anything
like JSF yet... I want to get my base solid first.

When you started with JSF, was it challenging/easy to get started with
it? The current project only has two JSPs with these needs.

Last night I implemented what I described and it worked well... so
anything using JSF would be probably notched as a next iteration item.
 

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,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top