You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Robert Taylor <rt...@mulework.com> on 2001/02/14 21:39:07 UTC

More HTML element examples

I've been through the examples included in the struts0.5 release.
Specifically I'm looking for examples of using the <select> element with
dynamically generated <options>. I have seen the <options> element and read
its definition but still am unclear on how to use it.

For example, I want to retrieve some data from the database, populate a
HashMap and have the options list generated using the hash key as the value
attribute of the option tag and the hash value as the body of the option
tag.

If I have missed this somewhere in the documentation, I apologize. I scanned
the resources and did not see anything that looked like "html element
examples".

Robert Taylor
rtaylor@mulework.com
770.891.9858 (this may change soon)
http://www.mulework.com


Re: More HTML element examples []

Posted by Dan Connelly <ds...@adelphia.net>.
Robert Taylor wrote:
> I've been through the examples included in the struts0.5 release.
> Specifically I'm looking for examples of using the <select> element with
> dynamically generated <options>. I have seen the <options> element and read
> its definition but still am unclear on how to use it.
> 

I, too, found the documentation inadequate in this area.   However, the question has apparently been brought up on this listserv before.   There are examples in the listserv archive.  The fundamental idea is the same as is used for the "User Database" in the Example example.

Have a look at http://marc.theaimsgroup.com/    Its a searchable Mail ARChive (MARC) covering this listserv (and lots of other interesting ones too).  Just search on "options" for struts-user.

The thread "Need some help please" explores the use of the <options> tag.  (The "Subject" text here could use some help!  But, Hey, the same goes for "More HTML element examples".)   Continuing...  The "Need some ... " thread is slightly misleading.  It has examples that use the <struts:enumerate> tag.  I believe that that tag has now been replaced by <logic:iterate>, a switch which undoubtedly contributes to the confusion on this topic.

Also, have a look at the "Options Tag" thread (Yes, good Subject text here), but some indications in that thread that there are existing bugs in indexed array accesses.   (??)

Ted H's reply on the "Need some.."  thread indicates that a Struts "collection"  should be synthesized from a "database."  Maybe, maybe not.  I can see that a "static" collection, which is often we really want, would be better derived from a Properties file.  However, in either case, the preferred method in Struts for instantiating such a collection (for use with <html:iterate>) is to have an made-to-purpose application Servlet which you code up to do the "heavy lifting".  The collection get instantiated in that Servlet's init method, when the application is loaded into the server container.  Bottom line, you roll your own.  See "DatabaseServlet.java" in the Example app, for an example.

If you are reading Hans Bergten's book on JSPs, which discusses a Struts-like architecture, you might naively assume that the Struts built-in ActionServlet would contain some packaged support for cons-ing up your collections for you.  Not in Rev 1.0 by what I see.  I don't see it on the Rev 1.1 ToDo list either, although "Better Database Support" could be stretched in that direction.  Maybe, in that case, we should be looking at better J2EE Support instead.  (IMHO Application Scope Bean collections are not at all the same thing as Persistent EJB collections, which is where "databases" really fit in.  Just my opinion.) 

OK.  OK.  I'm rambling.   

<html:options> isn't the only area where coding examples that use (ordered) collections under Struts would be helpful.  Has anyone got an example of  Previous and Next submit buttons to scan over a collection for FormBeans?  That should be simple, and nice.

Better yet, how about an example of an IE5.5-style Floating Popup containing a scrolling list of FormBean ids that would dynamically update of the parent page when clicked ...?   OK.  I'm still rambling.   And futuring.  (Except that it should be possible to do a very sweet, very MVC Floating Popup now, with Struts 1.0, if you limit yourself to IE5.5)


Dan Connelly
South Burlington, Vermont