You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Lynn Stevens <ly...@hotmail.com> on 2004/08/23 05:22:26 UTC
Re: setting a collection in my form bean using iterate or forEach
No I am not getting any errors. I would paste the code now, but its at work
and I am at home...I will paste it in the moring. If I am inside an
iterate tag, it does not iterate at all because the String[] is empty. If I
change to a for:Each jstl tag and tell it to loop say 3 times, it prefills
all of my html:textfields to show the pointer location of the String[]. Its
as though it does not recognize that I am trying to get each textfield to be
one item in the String[].
With the Iterate tag, if the String[] is empty, then it just thinks there is
nothing to iterate over and none of the textfields appear. Oddly, when I
prefill the String[] with n empty Strings, it will make my n textfields, but
in each textfield it has the pointer location of the String. If I then edit
the text field and type something in, it does give me an error...it can not
cast the String to a String[]. This tells me that it expects each textfield
to be a String[] and does not recognize that I am trying to *fill* the
String[].
Sorry, I hope this makes sense...if not I can paste the actual code
tomorrow...I am thinking that I can always get the info from the request
itself and not use the form bean by giving each textfield the name of
myField + i if i is the current iteration, but that seem wrong.....
>From: Rick Reumann <st...@reumann.net>
>Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>To: Struts Users Mailing List <us...@struts.apache.org>
>Subject: Re: setting a collection in my form bean usin iterate or forEach
>Date: Sun, 22 Aug 2004 21:49:16 -0400
>
>Lynn Stevens wrote:
>
>>If I put a String[] or ArrayList in my
>>DynaActionForm, this does not seem to work.
>
><snip>
>
>>Does anyone know if this is possible? Its driving me mad!
>
>Sure it'll work. Be more specific of how you are setting stuff up (paste
>the dyna/action form definition and the form code. Also, as someone else
>asked, what 'isn't work' - are you getting errors?
>
>
>--
>Rick
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: setting a collection in my form bean using iterate or forEach
Posted by Rick Reumann <st...@reumann.net>.
Lynn Stevens wrote:
> No I am not getting any errors. I would paste the code now, but its at
> work and I am at home...I will paste it in the moring. If I am inside
> an iterate tag, it does not iterate at all because the String[] is
> empty.
But why is empty? In other words if these are text fields you expect to
filled out then it shouldn't be empty when you get to the form. That is
if you plan to loop/iterate over a form field then it needs to be
prepopulated with what you want.
> If I change to a for:Each jstl tag and tell it to loop say 3
> times, it prefills all of my html:textfields to show the pointer
> location of the String[].
Well in the above when you say it "prefills" all of you textfields, you
don't mean it's filling them with appropriate text field values.
Assuming you want to use a String[], what I think you want to do is...
(Lets assume you are doing an update of maybe a String[] array of
automobile names)...
in a setUp dispatch method call backend and then populate your form
String[] automobileNames with the names. )One important thing to note
though is that you will have to have intialized your array in the form
to at least not be null or else you'll probably end up with some
NullPointer Exceptions)
Now forward to form....
<c:forEach items="${yourForm.automobileNames}" var="name">
<html:text property="automobileNames" value="${var}"/>
</c:forEach>
Something like the above should work.. then when the form submits you'll
have the String[] automobileNames populated with all the names (which in
the above could have been edited by the user).
--
Rick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org