Kevin,

I finally got
<logic:iterate ... <html:text ... indexed="true"/> ... </logic:iterate>
to work.

The sample code came from
http://www.mail-archive.com/[email protected]/msg12084.html
Thank you Dave.

I built Dave's code on top of struts-example. All necessary code is attached.
On the index.jsp page there are two links

<html:link page="/indexed.do">Iterate html:text indexed example</html:link>

<html:link page="/ShowParameters.do">From Dave Iterate html:text indexed example</html:link>

The first one, indexed.do, doesn't work. Gives IndexOutOfBoundException.
The second, ShowParameters.do, works. :D

I still trying to figure out the differences between those two...

Good luck!
Leo



From: Kevin HaleBoyes <[EMAIL PROTECTED]>
Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Subject: struggling with indexed/repeating input fields
Date: Tue, 19 Nov 2002 07:10:15 -0800 (PST)

I've asked this question several times on this mailing list but
I've never received an answer that would help. I've dug a bit
deeper and understand more about the problem but I'm still really
struggling with indexed/repeating input fields so I thought I'd
ask again. I'm starting to wonder if it is possible.

In my ActionForm I have an array property that is initialized to
null (I don't know the values until the Action executes).
I have a getter
that returns the entire array and a setter that takes an array.
I also have indexed getters and setters. The array is of another
class (that simply has two strings in it with the default/empty
constructor and getters and setters).

In my (edit) action I construct an array and call the setter in the
action form instance (that I just created). I then forward to a JSP
page that has a <logic:iterate> tag and <html:text> tags all within
a form tag. The form has a <html:submit> that calls my save action.
The save action simply forwards to a "confirmation" JSP page that
has a similar iteration to display the input values.

The initial "edit" form gets displayed properly - the expected
number of iterations are performed and the expected values of the
input fields is shown. When I press the submit button things break.
I know that isn't terribly descriptive but "how" it breaks depends
on how I form the <html:text> tags - there are two cases that I've
tried.

In the first case, I use the following in the "edit" JSP form:

<logic:iterate id="li" name="IndexedForm" property="lineItem">
<html:text name="li" property="itemNo" indexed="true"/>
<html:text name="li" property="desc" indexed="true"/>
</logic:iterate>

As I said, it displays properly. I change the "desc" text and hit
the submit button and end up getting an exception:

ApplicationDispatcher[/cml] Servlet.service() for servlet
jsp threw exception
org.apache.jasper.JasperException: No collection found

In the "save" action I printed the toString() of the input form
before forwarding to the JSP page and can see that the array is
in fact null. Why is it null? Who is responsible for instantiating
an array for that field - struts or the application? If it is the
application, how can it know how big to make the array?


In the second case, I use the following in the "edit" JSP form:

<logic:iterate id="li" name="IndexedForm"
property="lineItem" indexId="i">
<% String prop1 = "lineItem[" + i + "].itemNo"; %>
<html:text property="<%= prop1 %>" size="30"/>
<% String prop2 = "lineItem[" + i + "].desc"; %>
<html:text property="<%= prop2 %>" size="30"/>
</logic:iterate>

Again, it displays properly. I change the "desc" text and hit the
submit button and end up getting an exception:

StandardWrapperValve[action]: Servlet.service() for
servlet action threw exception
javax.servlet.ServletException: BeanUtils.populate
...
Caused by: java.lang.NullPointerException
at
com.illuminat.cml.IndexedForm.getLineItem(IndexedForm.java:286)


This happens even before it calls the "save" action.


So, I'm at a loss as to how to handle indexed or repeating fields.
I've looked at the code in html-setters.jsp and TestBean from the
exercise-taglib in the distribution but that uses fixed size
arrays and static initializers. It hasn't been simple to go from
that to a variable number of array elements and non-static
(from a database) initialization.

I've also looked in the archives and
on the current mailing list and found nothing. Actually, I've been
seeing more questions regarding indexed properties lately
(mostly using
DynaBeans) but they are generally going un-answered or not coming
up with solutions, just more questions. This is not a complaint
as I know everyone is very busy but it does mean that I've not found
anything in the archives.

Help would be most appreciated. Sample code would be even nicer!
Is it even possible with Struts (version 1.1b2)?
I can furnish code or a better explaination if needed.

Kevin




__________________________________________________
Do you Yahoo!?
Yahoo! Web Hosting - Let the expert host your site
http://webhosting.yahoo.com

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

_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail

Attachment: works.zip
Description: Zip compressed data

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


Reply via email to