Hi,

I am working on getting a drop-down list of values that are generated from a
DB call to show up on my page, both before and after validating the page.

It was working earlier, when I was just making a nice ArrayList of my
objects and adding the list to the session.  (It looked to me like it had to
be in the session, since the request lost the ArrayList after validate().)
That didn't seem like the best plan, so I tried to make my list part of my
DynaValidatorForm.

(Now if you all say that its perfectly fine to add the ArrayList of options
to the session, I'll take your word for it and stop there.)

So, then I changed my form to add the ArrayList like such:
    <form-bean name="projectForm"
               type="org.apache.struts.validator.DynaValidatorForm" >
               <form-property name="name"        type="java.lang.String" />
               <form-property name="description" type="java.lang.String" />
               <form-property name="weight"      type="java.lang.String" />
               <form-property name="active"      type="java.lang.String" />
               <form-property name="projCodeName" type="java.lang.String" />
               <form-property name="projCodeNames"
type="java.util.ArrayList"/>.
    </form-bean>

The objects that are in the ArrayList are beans that have a few attributes.

So in my .jsp, I've got:
<html:select property="projCodeName">
  <html:options property="projCodeNames" />
</html:select>

This started out being pretty ugly.  It looked like it was calling
toString() on my bean.  I added a toString() method and then that's what I
got back, as both my option's value and label.  I suppose this makes sense,
since I haven't told it which attributes to put out for either.  The problem
is, I don't see how to specify which attributes to use.

I've read and re-read:
http://jakarta.apache.org/struts/userGuide/struts-html.html#options
and I guess I'm missing something, because I couldn't find the answer there.

I suppose this would work if my ArrayList contained nothing but Strings.
But then how would I get my value and label to be different?  It appears
that I would need to have two collections: one for the labels and one for
the values.

As I'm learning struts, it seems like there's lots of slick ways to do
things, and having 2 collections of Strings doesn't seem very slick.  So I'm
assuming I'm missing something.  Could someone please clue me in as to what
I'm doing wrong or not understanding?

Thanks in advance,
Janice
(Victoria, BC)


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

Reply via email to