<html:select />, <html:option />, <html:options />, <html:optionsCollection />
The <html:select /> tag renders a drop down selection or list box to the end user. You can specify the options for the <html:select/> tag with <html:select />, <html:option />, <html:options />, <html:optionsCollection /> tags. The <html:option /> tag generates an option for the select tag (<option>). The <html:options /> tag is used to generate a group of HTML <option> elements inside of the select tag. The <html:optionsCollection /> tag is also used to generate a list of HTML <option> elements from a collection of JavaBeans. Here is an example of creating a multiple that gets its values from one collection and its labels from another: <html:select property="multipleSelect" size="10" multiple="true"> <html:options name="multipleValues" labelName="multipleLabels"/> </html:select> Notice that it sets the multiple attribute to true, this tells the custom tag to render a select input that allows multiple items in the selection list to be selected. When you set multiple="true", you have to make sure that the corresponding property in the ActionForm subclass is an array type. The html:options tag uses the collection. The first collection is called the multipleValues, and is used to specify the values that are submitted to the action if the item is selected. The second collection multipleLabels is used to populate the labels for the corresponding values in the first collection. <html:select property="collectionSelect" size="10" multiple="true"> <html:options collection="options" property="value" labelProperty="label"/> </html:select> A variation of the html:options tag specifies a single collection with a collection attribute. Then it specifies an attribute that will contain the value, and an attribute that specifies the label. The tag will iterate over each item in the options collection of and call item.getValue() for the value and item.getLabel() for the label. The property names can be any property name that the beans in the collection support. Typically in struts when you're accessing a bean in a certain scope, then you always use three attributes namely: name, property, and scope. The html:options breaks all the rules when it comes to dealing with collection. If the html:optionsCollection uses the standard trinity of attributes as follows: <html:optionsCollection name="testbean" property="beanCollection" scope="session" label="label" value="value" /> The above uses the trinity of attributes to grab the test bean out of session scope and use its collection property called beanCollection. The collection has a list of JavaBeans of a certain type. The JavaBean has a label property and a value property which are used by the label and value attributes to extract the label and values (the property of the JavaBean does not be called label and value). Rick Hightower Developer Struts/J2EE training -- http://www.arc-mind.com/strutsCourse.htm Struts/J2EE consulting -- http://www.arc-mind.com/consulting.htm#StrutsMentoring -----Original Message----- From: Christian Froemel [mailto:[EMAIL PROTECTED] Sent: Thursday, January 15, 2004 3:34 AM To: [EMAIL PROTECTED] Subject: Problem accessing database and <html:options> Hello, I am a newbie with Struts and JSP-Programming. I want to program the following: I want to access a database (oracle) and want to get the results (i.e. firstname and lastname). I connect to the database with JDBC-Calls within the execute-method in the Action-Class ( or should I use the option data-source in the struts-config? ) and store the results in an Array-List. With the results I want to create a select. But how I use the command <html:options collections=??? ... > and display the results? I will be very glad, if somesome can help me. An small example would be helpful ;) Thanks in advance, Christian --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]