tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Duffy <duff...@yahoo.com>
Subject Re: Populating One <select> Based On The Value In Another
Date Wed, 07 May 2003 13:00:28 GMT

Hi Brian,

I agree - the Maturo document is a good effort, but
the details on this particular problem aren't there.

6 boxes on one page - oh, my.  That must be something
intensive like an insurance policy issue screen.  That
industry has some very stringent GUI requirements. 
Lots of data, lots of forms, difficult validations.

I agree - you've got a lot of work to do with six
boxes.  

It bothers me a bit to have to make that many round
trips just to fill out a bloody form.  

The alternative is to send a big block of data down
all at once and sort it out on the client.  I haven't
been successful at figuring that out.  The round-trip
might not be that bad for a case like yours, which
would require a lot of data to come down to the
client.

Thanks so much for the links.  I'll be sure to give
them a look.  If I hear about anything else good, I'll
let you know. 

Good luck with your project! - MOD



--- Brian McSweeney <brian.mcsweeney@aurium.net>
wrote:
> Hi Michael,
> 
> > 3. Larry Maturo's document "Using Struts"
> describes
> > this technique, so I got the idea that Struts
> would
> > handle this event the same way it would a submit
> > button click.
> 
> Unfortunately his document doesn't really give a
> strong
> example. I'm trying to do it for 6 select boxes on
> the one
> page. The problem I see with this approach is that
> I'll
> need some way to know which select box to update
> based
> on returning from the action. I can possibly do this
> with
> hidden values, but it seems a little hacky.
> 
> At any rate, it is a common thing. I can point you
> to some
> resources if you want:
> 
>
http://www.mattkruse.com/javascript/dynamicoptionlist/
> 
> but the problem is, if you want to do this for many
> lists,
> it gets more difficult. For example, check out
> 
>
http://list.auctions.shopping.yahoo.com/0-submit.html
> 
> It uses javascript, but I think lots of it is hard
> coded - yuck
> Ebay does a similar thing but uses an applet
> instead.
> 
> anyway,
> any other good ideas out there?
> 
> 
> 
> ----- Original Message -----
> From: "Michael Duffy" <duffymo@yahoo.com>
> To: "Tag Libraries Users List"
> <taglibs-user@jakarta.apache.org>
> Sent: Wednesday, May 07, 2003 1:20 PM
> Subject: Re: Populating One <select> Based On The
> Value In Another
> 
> 
> >
> > Hi Brian,
> >
> > 1. It looks like the onchange event in the
> <select>
> > tag must do a submit to get back to the server,
> like
> > this:
> >
> > onchange="document.forms[0].submit()"
> >
> > But then you've noted that in your second
> question.
> >
> > 2. My understanding is that the submit goes to the
> URL
> > in the <form> tag.  In my case, it's a front
> > controller servlet, so that's no problem.
> >
> > 3. Larry Maturo's document "Using Struts"
> describes
> > this technique, so I got the idea that Struts
> would
> > handle this event the same way it would a submit
> > button click.
> >
> > Seems like a pretty common problem to me.  If I
> had an
> > app with a drop-down for states, followed by
> another
> > for zip code, I would want to be able to populate
> the
> > zip code drop-down with the values for the
> selected
> > state.  There's GOTTA be a well-known solution out
> > there! - MOD
> >
> >
> > --- Brian McSweeney <brian.mcsweeney@aurium.net>
> > wrote:
> > > Hi all,
> > > I've been following this thread with interest.
> I'm
> > > trying to do exactly
> > > the same thing. I'm working with struts  and
> > > Michael's
> > > suggested solution seems the easiest to me, even
> > > though it does
> > > necessitate going back to the server each time.
> > >
> > > The basic idea is - submit to an action on
> change of
> > > the select option,
> > > then get the children of the selected option and
> put
> > > them in the next list.
> > >
> > > The code for my three lists are below:
> > >
> > >   <table border=0 cellpadding=4 cellspacing=1>
> > >     <center>
> > >     <tr>
> > >         <td valign=top>1.</td>
> > >             <br>
> > >             <html:select property="orgId" size=5
> > > width = 250
> > > onchange='document.forms[0].submit()'>
> > >                 <html:options
> collection="orgList"
> > > property="value"
> > > labelProperty="longName"/>
> > >             </html:select>
> > >         </td>
> > >         <td valign=top>2.</td>
> > >             <br>
> > >             <html:select property="orgId" size=5
> > > width = 250
> > > onchange='document.forms[1].submit()'>
> > >                 <html:options
> collection="orgList"
> > > property="value"
> > > labelProperty="longName"/>
> > >             </html:select>
> > >         </td>
> > >         <td valign=top>3.</td>
> > >             <br>
> > >             <html:select property="orgId" size=5
> > > width = 250
> > > onchange='document.forms[2].submit()'>
> > >                 <html:options
> collection="orgList"
> > > property="value"
> > > labelProperty="longName"/>
> > >             </html:select>
> > >         </td>
> > >     </tr>
> > >   </table>
> > >
> > > However, my problem is that I'm new to javascipt
> and
> > > I don't know how it
> > > interacts with struts.
> > > So I have  a few questions:
> > >
> > > 1) Does the onchange method call an inbuild
> > > javascript function?
> > >
> > > 2) How do I link up the
> document.forms[var].submit(
> > > ), to a struts action
> > >
> > > 3) Is there some way on the action side to tell
> > > which form submitted?
> > >
> > > I know these are kinda struts related questions,
> but
> > > I thought that I'd keep
> > > it on the
> > > same thread.
> > > thanks very much,
> > > Brian
> > >
> > >
> > >
> > > ----- Original Message -----
> > > From: "Michael Duffy" <duffymo@yahoo.com>
> > > To: "Tag Libraries Users List"
> > > <taglibs-user@jakarta.apache.org>
> > > Sent: Tuesday, May 06, 2003 6:49 PM
> > > Subject: Re: Populating One <select> Based On
> The
> > > Value In Another
> > >
> > >
> > > >
> > > > You're correct, of course, James, but I don't
> want
> > > any
> > > > SQL in my jsps.   The whole point of a front
> > > > controller is to get that kind of stuff out of
> the
> > > > JSPs.
> > > >
> > > > Database access is a back-end process, to be
> done
> > > on
> > > > the server side only IMHO.  JSPs should only
> be
> > > for
> > > > presentation.
> > > >
> > > > BTW, there's a nice Struts-based idea from
> Larry
> > > > Maturo of Athens Group that might help:
> > > >
> > > >
> > >
> >
>
http://stealthis.athensgroup.com/presentations/Model_Layer_Framework/Struts_
> > > Whitepaper.pdf
> > > >
> > > > It doesn't save a trip to the server, but it
> does
> > > > accomplish the "populate the second combo box
> > > after
> > > > selecting the first" goal.
> > > >
> > > > I'll be refactoring my work to use Struts once
> > > I've
> > > > got the whole thing working, so I'll probably
> take
> > > > advantage of Larry's technique at that time.
> > > >
> > > > Thanks - MOD
> > > >
> > > > --- James Smith <jksmith@email.arizona.edu>
> wrote:
> > > > > You can't go from JavaScript back to JSTL
> > > without
> > > > > another trip to the
> > > > > server; however, you certainly can use JSTL
> tags
> > > to
> > > > > create a map within
> > > > > JavaScript code, something like this:
> > > > >
> > > > > <sql:query var="rs">
> > > > >     select ID, Name from tblSomeTable
> > > > > </sql:query>
> > > > >
> > > > > <script language="javascript">
> > > > >     firstSelectHashMap = new Array();
> > > > >     <c:forEach var="row" items="${rs.rows}">
> > > > >         <sql:query var="rs2">
> > > > >             select ID, Name from
> tblChildTable
> > > where
> > > > > ParentID = ?
> > > > >             <sql:param value="${row.ID}" />
> > > > >         </sql:query>
> > > > >         secondSelectHashMapChoice = new
> Array();
> > > > >         <c:forEach var="row2"
> > > items="${rs2.rows}">
> > > > >            
> secondSelectHashMapChoice['<c:out
> > > > > value="${row2.ID}" />'] =
> > > > > '<c:out value="${row2.Name}" />';
> > > > >         </c:forEach>
> > > > >         firstSelectHashMap['<c:out
> > > value="${row.ID}"
> > > > > />'] = tempChild;
> > > > >     </c:forEach>
> > > > > </script>
> > > > >
> > > > > My JavaScript is a bit rusty but it should
> look
> > > > > something like that.
> > > > > Anyway, that whole piece of code makes your
> page
> > > a
> > > > > lot larger, and then,
> > > > > when a select occurs, you've got to write
> the
> > > > > JavaScript to depopulate your
> > > > > second select box and repopulate it with the
> > > chosen
> > > > > secondSelectHashMapChoice.  So it's possible
> to
> > > code
> > > > > but it seems fairly
> > > > > nasty.  The second trip to the server is
> > > probably
> > > > > much wiser, unless a
> > > > > JavaScript guru out there has a brilliant
> > > method,
> > > > > probably involving forcing
> > > > > submits from forms within internal frames
> hidden
> > > by
> > > > > moving them off the page
> > > > > with CSS-P.
> > > > >
> > > > > James Smith
> > > > > Application Systems Analyst, Treistman
> Center
> > > > > College of Fine Arts, University of Arizona
> > > > >
> > > > > ----- Original Message -----
> > > > > From: "Michael Duffy" <duffymo@yahoo.com>
> > > > > To: "Tag Libraries Users List"
> > > > > <taglibs-user@jakarta.apache.org>
> > > > > Sent: Tuesday, May 06, 2003 9:47 AM
> > > > > Subject: RE: Populating One <select> Based
> On
> > > The
> > > > > Value In Another
> > > > >
> > > > >
> > > > > >
> > > > > > I've got a front controller servlet that
> takes
> > > > > > requests, executes commands, puts results
> into
> > > the
> > > > > > request, and forwards them onto the next
> page.
> > > > > The
> > > > > > next page can certainly do this:
> > > > > >
> > > > > > <jsp:useBean id="something"
> > > > > class="java.util.Map"/>
> > > > > >
> > > > > > Now I can access the map by writing:
> > > > > >
> > > > > > "${something['key']}"
> > > > > >
> > > > > > If the Map has String keys and
> java.util.List
> > > > > values,
> > > > > > I can get the value and stuff it into a
> JSTL
> > > > > > <c:forEach> tag.
> > > > > >
> > > > > > Actually , I haven't gone to ANY trouble
> yet
> > > > > because
> > > > > > I've just started on this effort.  ;)  It
> was
> > > just
> > > > > an
> > > > > > idea.  I thought that if there was a way
> to
> > > get
> > > > > the
> > > > > > value out of DHTML and into JSTL that I
> was
> > > > > ignorant
> > > > > > of I'd be glad to know it.
> > > > > >
> > > > > > But the dearth of information has brought
> me
> > > to
> > > > > the
> > > > > > same conclusion that you're drawing: it's
> not
> > > > > > possible.  I'll just populate both
> drop-downs
> > > at
> > > > > the
> > > > > > same time.  Thanks. - MOD
> > > > > >
> > > > > >
> > > > > > --- Wendy Smoak <Wendy.Smoak@asu.edu>
> wrote:
> > > > > > > Michael wrote:
> > > > > > > > Exactly.  It's a choice between doing
> it
> > > on
> > > > > the
> > > > > > > client
> > > > > > > > side or enduring another round-trip to
> the
> > > > > server.
> > > > > > >  I
> > > > > > > > know how to get it from the server,
> but I
> > > was
> > > > > > > hoping
> > > > > > > > that I could send a java.util.Map down
> > > when
> > > > > the
> > > > > > > page
> > > > > > > > is rendered and save myself a trip.
> > > > > > >
> > > > > > > All the Java/JSP/JSTL code executes on
> the
> > > > > server,
> > > > > > > so I don't see where you
> > > > > > > could "send" a Map down to the client
> side.
> > > > > Maybe
> > > > > > > an applet?  You could
> > > > > > > surely render the *contents* of the Map
> into
> > > a
> > > > > > > JavaScript data structure.
> > > > > > > (Does JavaScript have a Map structure?)
> And
> > > then
> > > > > use
> > > > > > > client-side JavaScript
> > > > > > > to populate the second drop-down once
> the
> > > user
> > > > > has
> > > > > > > made a selection from the
> > > > > > > first.
> > > > > > >
> > > > > > > > But this is the first time I've had
> the
> > > > > problem of
> > > > > > > > populating one drop-down using the
> choice
> > > from
> > > > > > > > another.  I know how to get the
> selection
> > > from
> > > > > the
> > > > > > > > first box out of JavaScript.  Getting
> that
> > > > > value
> > > > > > > into
> > > > > > > > JSTL and the EL is the thing that I'm
> > > fuzzy
> > > > > on.
> > > > > > >
> > > > > > > It's one or the other.  Since JavaScript
> is
> > > > > > > client-side, and JSTL/EL is
> > > > > > > server-side, you can't get the value out
> of
> > > > > > > JavaScript and into JSTL.  If
> > > > > > > you want to save a trip to the server,
> then
> > > I
> > > > > don't
> > > > > > > believe JSTL will be of
> > > > > > > any help.
> > > > > > >
> > > > > > > How much of a load will this site be
> under?
> > > Is
> > > > > an
> > > > > > > extra round trip to the
> > > > > > > server really that important?  You may
> be
> > > going
> > > > > to a
> > > > > > > lot of trouble to avoid
> > > > > > > something that isn't really going to be
> a
> > > > > problem.
> > > > > > >
> > > > > > > --
> > > > > > > Wendy Smoak
> > > > > > > Applications Systems Analyst, Sr.
> > > > > > > Arizona State University PA Information
> > > > > Resources
> > > > > > > Management
> > > > > > >
> > > > > >
> > > > > >
> > > > > > __________________________________
> > > > > > Do you Yahoo!?
> > > > > > The New Yahoo! Search - Faster. Easier.
> Bingo.
> > > > > > http://search.yahoo.com
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
---------------------------------------------------------------------
> > > > > > To unsubscribe, e-mail:
> > > > > taglibs-user-unsubscribe@jakarta.apache.org
> > > > > > For additional commands, e-mail:
> > > > > taglibs-user-help@jakarta.apache.org
> > > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > >
> >
>
---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail:
> > > > > taglibs-user-unsubscribe@jakarta.apache.org
> > > > > For additional commands, e-mail:
> > > > > taglibs-user-help@jakarta.apache.org
> > > > >
> > > >
> > > >
> > > > __________________________________
> > > > Do you Yahoo!?
> > > > The New Yahoo! Search - Faster. Easier. Bingo.
> > > > http://search.yahoo.com
> > > >
> > > >
> > >
> >
>
---------------------------------------------------------------------
> > > > To unsubscribe, e-mail:
> > > taglibs-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail:
> > > taglibs-user-help@jakarta.apache.org
> > > >
> > >
> > >
> > >
> >
>
---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > > taglibs-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail:
> > > taglibs-user-help@jakarta.apache.org
> > >
> >
> >
> > __________________________________
> > Do you Yahoo!?
> > The New Yahoo! Search - Faster. Easier. Bingo.
> > http://search.yahoo.com
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> taglibs-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> taglibs-user-help@jakarta.apache.org
> >
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> taglibs-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Mime
View raw message