Superb answer Bill.

I've coded the following which correctly gets the OptionsCollection, but
I'm stumped as to what to substitute in place of 'MyForm.key':

<tr>
    <th align="right">
      Type:
    </th>

    <td align="left">
     <logic:notEqual name="surveyForm" property="action" scope="request"
value="Delete">
      <html:select property="type">
        <html:optionsCollection name="surveyTypes"
property="optionsCollection"/>
      </html:select>
      </logic:notEqual>
      <logic:equal name="surveyForm" property="action" scope="request"
value="Delete">
        <html:hidden property="type"/><c:out
value="${surveyTypes.optionsMap[MyForm.key]}"/>
      </logic:equal>

    </td>
  </tr>











There are a couple of ways of doing this. I think the best approach is
to wrap your collection in a JavaBean that is stored in the session.
Something like the following:

public class OptionsHolder {
   Map options = new HashMap();
   public OptionsHolder() {
     options.put("key1", new LabelValueBean("foo","key1"));
     options.put("key2", new LabelValueBean("foo","key1"));
   }
   public Collection getOptionsCollection() {
     return options.values();
   }
   public Map getOptionsMap() {
     return options;
   }
}

You can then use the getOptionsCollection() method to render the options
in the first form. Then in the page where you want to display the value
for the key, you can use JSTL. Assuming the ServletContext attribute
name were "optionsHolder" and the key was in the property 'key' on the
form:

<c:out value="${optionsHolder.optionsMap[MyForm.key]}"/>

Another alternative is to create a mapped property in the OptionsHolder
bean; then use Struts support for mapped properties in the bean:write tag.

Finally, a third alternative would be to fetch the value in the action
that processes the form. Extract the desired value then set it as a
request attribute for display on the subsequent JSP. With this approach
you might not need to use the OptionsHolder class and instead just
iterate over the collection looking for a match.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to