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 / April 2006

Tip: Looking for answers? Try searching our database.

JSP mapping an HTML control to a Java bean

Thread view: 
ccjjharmon@gmail.com - 10 Apr 2006 21:56 GMT
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?
Danno - 11 Apr 2006 00:05 GMT
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.
ccjjharmon@gmail.com - 11 Apr 2006 13:01 GMT
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.
Roedy Green - 11 Apr 2006 20:39 GMT
>When you started with JSF, was it challenging/easy to get started with
>it? The current project only has two JSPs with these needs.

You would probably want to get basic Servlets and JSP under your belt
first, so you understand the underpinnings.

see http://mindprod.com/jgloss/servlet.html
http://mindprod.com/jgloss/jsp.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Danno - 11 Apr 2006 23:11 GMT
Second that. ;)


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.