struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Charlie Toohey <ctoo...@pacbell.net>
Subject Re: html:text tag "indexed" attribute
Date Sun, 02 Feb 2003 22:09:44 GMT
Thanks David. I appreciate your help.

My conclusion is that the html:text "indexed" attribute is only intended for 
collections of beans which have properties, not for collections of Strings 
which do not have properties. The generated "name" attribute for the HTML tag 
of name[nn].property simply does not apply to a collection of some object 
which does not have properties.

I figured out how to do it using the "indexId"  of the logic:iterate tag. 
This solves both the problem of populating the HTML text tag with the correct 
value, and creating the correct "name" attribute for the HTML text tag, so 
that my form bean is populated correctly on submit.

<logic:iterate name="aForm" property="stringArray" id="aString" 
indexId="index">
  <html:text property='<%="aString[" + index + "]"%>' />
 </logic:iterate>

I'm sure that there is a slicker way to do this with Struts-EL or JSTL, but I 
haven't gotten there yet. Need more time !

Thanks for all your help.

- Charlie


On Saturday 01 February 2003 11:24 pm, you wrote:
> >>>>> "Charlie" == Charlie Toohey <ctoohey@pacbell.net> writes:
>
>     Charlie> Thanks David. That worked for the value attribute:
>     Charlie> <logic:iterate name="aForm" property="stringArray"
> id="aString" > Charlie>    <html:text indexed="true" property="aString"
> value='<%= aString.toString() Charlie>  %>' />
>     Charlie> </logic:iterate>
>
>     Charlie> BUT, this resolves to an HTML text tag of:
>     Charlie> <input type="text"
> name="org.apache.struts.taglib.html.BEAN[0].aString" Charlie>
> value="somevalue">
>
>     Charlie> This is my larger question --- what I'm trying to get is
>     Charlie> <input type="text" name=aString[0] value="somevalue">
>
>     Charlie> Using the Struts html:text tag with indexed="true", I am
> iterating over a Charlie> collection of String objects, NOT a collection of
> bean objects with Charlie> properties. Therefore, instead of using the bean
> name for the "name" Charlie> attribute and the bean property for the
> "property" attribute, like all of the Charlie> examples I have seen, I do
> not know what to put for the "name" and "property" Charlie> attributes,
> because this is a collection of Strings, not beans, and the Charlie> String
> objects do NOT have a property.
>
>     Charlie> Please help !     I've been trying to get this to work for 2
> days now.
>
> This is where it gets a little tricky to visualize, and I'm not sure I'm
> going to get this right, but I'll give it a try.
>
> First of all, you should change "aString" to something that doesn't have a
> capital in the first two characters of the property name.  I believe that
> triggers some funny behavior in the JavaBeans spec.  If you just change it
> to "astring" or "someString", that would work fine.
>
> Now, try adding a "name" parameter to your "html:text" tag.  I don't know
> what to call it yet, but let's call it "stringObj".
>
> Now, add an indexed getter (may not need the getter) and setter to your
> form bean, for the "stringObj" property.  The value parameter will be a
> "String".
>
> That may work.  Personally, I find "indexed" tags confusing, but I haven't
> tried to use them very much.  It seems to me that it's more understandable
> to build the array reference expression manually, and this is easier to do
> if you use Struts-EL, as the EL expressions are more concise than scriptlet
> expressions.

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message