Thanks David. 

I tried your suggestion although I still have no idea what to use for the 
value of "property" --- any way, I can't get it work. I can not get my .jsp 
to compile using your suggested scriptlet for the "value" attribute.
Here is what I have got:

<logic:iterate name="aForm" property="stringArray" id="aString">
..
        <html:text indexed="true" property="aString" value='<%= aString %>'  
/>
..
</logic:iterate>

This gives me the following exception:
cannot resolve symbol
symbol  : method setValue (java.lang.Object)
location: class org.apache.struts.taglib.html.TextTag
                          _jspx_th_html_text_0.setValue( aString );

My goal is to produce :
        <input type="text" name="aString[0]" value="somevalue">
        <input type="text" name="aString[1]" value="somevalue">
        ...

Another way of rephrasing my question is this: 
When using logic:iterate to iterate over a collection of beans, and using the 
Struts html:text tag with indexed="true", set name="beanName" and 
property="beanProperty". Fine so far.

However, I am iterating over a collection of Strings, which do not have 
properties, so I set indexed="true", name="aString", 
property="???"
This would resolve to <input type="text" name="aString[nn].???" . There is 
nothing to provide for the property because the String elements of the 
collection do not have properties. 

Any ideas ?

- Charlie



> Not quite.
>
> The value of the "value" attribute is used directly.  If you set it to
> "abc", then the text field will display "abc".  So, you would probably
> use '<%= aString %>'.
>
> If you have "indexed=true", that does the work of adding the brackets
> and array index to your resulting request parameter, you don't need to
> mangle the value yourself.  You do have to make sure you have an indexed
> setter on your form bean that agrees with your resulting indexed request
> parameter name.  This can get confusing, I know.
>
> -----Original Message-----
> From: Charlie Toohey [mailto:[EMAIL PROTECTED]]
> Sent: Friday, January 31, 2003 2:12 PM
> To: Struts Users Mailing List
> Subject: Re: html:text tag "indexed" attribute
>
> Thanks. I hope somebody knows the answer to the first question.
>
> re: my iterate over String array question --- I've got half of a
> solution,
> i.e. to pre-populate the form by supplying the "value" attribute. The
> other
> half is producing HTML input text tags with "name" attributes
> aString[0],
> aString[1],... so the form bean will be populated on submit. I assume
> that I
> would do the exact same thing you suggested for the value tag in the
> property
> tag, i.e.
> <html:text indexed="true" name="aBean" property='<%="aString[" +
> GET_INDEX +
> "]"%>'   value= '<%="aString[" + GET_INDEX + "]"%>' />
>
> So, the "property" and "value" attributes would have identical values ?
>
> However, this seems wrong, because based on your document, my HTML name
> would
> evaluate to "aBean.[nn].aString[nn], rather than aString[nn]
>
> Also, I still don't know where to get the index that I would put in
> GET_INDEX
> above ?
>
> Obviously I'm pretty lost here --- as I said, I can only find
> examples/discussions in the mailing archive with collections of beans,
> but
> nothing with collections of Strings, which is what I'm trying to do.
>
> Thanks,
> Charlie
>
> > I have a feeling that both could be interpreted as correct, but we
>
> could
>
> > use some other opinions on this.  I wrote the first one, so I'll
>
> update
>
> > it if this discussion points out a better way to say this.
> >
> > On your quandary with iterating over a collection of String objects,
> > instead of beans, it's useful to note that if the "value" attribute is
> > present, that is used as the value, but the "name/property" pair is
>
> used
>
> > as the request parameter name.  If the "value" attribute is missing,
>
> the
>
> > value is taken from the "name/property" pair.  In this case, you
>
> should
>
> > set the "value" attribute using an expression scriptlet (or an EL
> > expression, using Struts-EL), and define an appropriate formbean
>
> setter
>
> > method (based on the indexed name/property settings).
> >
> > -----Original Message-----
> > From: Charlie Toohey [mailto:[EMAIL PROTECTED]]
> > Sent: Friday, January 31, 2003 12:07 PM
> > To: [EMAIL PROTECTED]
> > Subject: html:text tag "indexed" attribute
> >
> > Two things regarding using the "indexed" attribute of the Struts
> > html:text
> > tag.
> >
> > First, there is a disagreement between the Struts FAQ on indexed
> > properties
> > and the Struts HTML tag docs.
> >
> > The Struts FAQ
> > http://jakarta.apache.org/struts/faqs/indexedprops.html
> > states that setting indexed="true" results HTML "name" attribute of
> > "name[nn].property", where name is the name attribute of the html:text
> > tag
> >
> > The Struts HTML tag docs
> > http://jakarta.apache.org/struts/struts-html.html#text
> > state that setting indexed="true" results in HTML "name" attribute of
> > "id[34].propertyName", where id is an attibute in the logic:iterate
>
> tag.
>
> > I'm sure there are many situations where the logic:iterate "id"
> > attribute
> > value is the same as the html:text "name" attribute, but not always.
> > Does
> > anyone know which or these docs is the correct one ?
> >
> >
> > Second thing I'm confused about has to do with iterating over a
> > collection of
> > String objects using logic:iterate and the html:text "indexed"
>
> attribute
>
> > set
> > to true. I have scoured the mailing list archives and see plenty of
> > discussion/examples about how to use these to iterate over a
>
> collection
>
> > of
> > beans --- the html:text tag would specify the desired property of the
> > bean as
> > the value of the "property" attribute. However, a String does not have
> > properties, so I don't understand how to do it for a collection of
> > Strings.
> >
> > e.g. using the Struts FAQ stringbean bean as an example, I believe the
> > following would successfully iterate over the LabelValue objects in
>
> the
>
> > stringbean's lvbeans array, using the value of the label property for
> > the
> > html text tag.
> >
> > <logic:iterate name="stringbean" property="lvbeans" id="labelValue">
> >   <html:text name="labelValue" property="label" indexed="true" />
> > </logic:iterate>
> >
> > resulting in HTML "name" attribute of labelValue[nn].label
> >
> >
> > but, lets say I have an array of String objects (stringArray) instead
>
> of
>
> > an
> > array of beans, and tried the following:
> >
> > <logic:iterate name="stringbean" property="stringArray" id="aString">
> >   <html:text name="aString" property="?????" indexed="true" />
> > </logic:iterate>
> >
> > My goal is have this generate HTML text tags with "name" attribute of
> > aString[0], aString[1], etc.
> > Since a String does not have a property, what would be used for the
> > property
> > value ??
> >
> > Thanks for any help !
> >
> > - Charlie
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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]
>
> ---------------------------------------------------------------------
> 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]

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

Reply via email to