Hi Rick,
Read your email (thanks again) and tried what you said:
I got a the following error:
org.apache.jasper.JasperException: An error occurred while evaluating custom action attribute "items" with value "${PrintSessionFormBean.slideLots}": Unable to find a value for "slideLots" in object of class "org.pfgrc.struts.maple.man.PrintSessionActionForm" using operator "." (null)
so then I tried pre-defining slideLots as so:
<bean:define id="theSlideLots" type="java.lang.String[]" name="PrintSessionFormBean" property="slideLots"/>
<c:forEach items="${theSlideLots}" var="lot">
<tr><td><b>Lot</b></td></tr>
<tr><td>Enter lot number:<br /><html:text property="theSlideLots" value="${lot}"/></td></tr>
<tr><td> </td></tr>
<tr><td nowrap>Scan slides for lot:</td></tr>
<tr><td><html:textarea property="slideBarCodes" rows="15" cols="29"/></td></tr>
</c:forEach>
which did not produce and error, but set the value in the text fields to be literally ${lot}
Any suggestions?
The jsp:
<c:forEach items="${PrintSessionFormBean.slideLots}" var="lot">
<tr><td><b>Lot</b></td></tr>
<tr><td>Enter lot number:<br /><html:text property="slideLots" value="${lot}"/></td></tr>
<tr><td> </td></tr>
<tr><td nowrap>Scan slides for lot:</td></tr>
<tr><td><html:textarea property="slideBarCodes" rows="15" cols="29"/></td></tr>
</c:forEach>
The DynaActionForm (its been subclassed to add a reset method):
<form-bean name="PrintSessionFormBean"
type="org.pfgrc.struts.maple.man.PrintSessionActionForm"
dynamic="true">
<form-property name="sessionID" type="java.lang.Integer"/>
<form-property name="slideTypeID" type="java.lang.Integer"/>
<form-property name="slideTypeName" type="java.lang.String"/>
<form-property name="slideTypeDesc" type="java.lang.String"/>
<form-property name="num_plates" type="java.lang.Integer"/>
<form-property name="plates" type="java.util.ArrayList"/>
<form-property name="num_entered_plates" type="java.lang.Integer"/>
<form-property name="entered_plates" type="java.util.ArrayList"/>
<form-property name="machineID" type="java.lang.Integer"/>
<form-property name="machineName" type="java.lang.String"/>
<form-property name="machineDesc" type="java.lang.String"/>
<form-property name="num_slides" type="java.lang.Integer"/>
<form-property name="slides" type="java.util.ArrayList"/>
<form-property name="num_plate_barcodes" type="java.lang.Integer"/>
<form-property name="plateBarCodes" type="java.lang.String"/>
<form-property name="slideBarCodes" type="java.lang.String"/>
<form-property name="entered_slides" type="java.util.ArrayList"/>
<form-property name="completed" type="java.lang.String"/>
<form-property name="arborID" type="java.lang.Integer"/>
<form-property name="fileName" type="java.lang.String"/>
<form-property name="numActualPlates" type="java.lang.Integer"/>
<form-property name="slideNo" type="java.lang.Integer"/>
<form-property name="dateCreated" type="java.lang.String"/>
<form-property name="operator" type="java.lang.String"/>
<form-property name="penID" type="java.lang.String"/>
<form-property name="printSessionName" type="java.lang.String"/>
<form-property name="crosslinked" type="java.lang.Boolean"/>
<form-property name="numSlideLots" type="java.lang.Integer" initial="0"/>
<form-property name="slideLots" type="java.lang.String[]"/>
<form-property name="slideGroups" type="java.lang.String[]"/>
</form-bean>
Snipet from the Action:
for (int i = 0; i < numSlideLots.intValue(); i++) { mySlideLots[i] = ""; } dvf.set("slideLots", mySlideLots);
mySlideLots = (String[]) dvf.get("slideLots"); for (int i = 0; i < mySlideLots.length; i++) { log.debug("lot " + i + ":"+ mySlideLots[i]); }
From: Rick Reumann <[EMAIL PROTECTED]> Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]> To: Struts Users Mailing List <[EMAIL PROTECTED]> Subject: Re: setting a collection in my form bean using iterate or forEach Date: Mon, 23 Aug 2004 00:48:58 -0400
Lynn Stevens wrote:
I think I see what you are saying, but in my case I am collecting information from the user that I have never seen before. Don't know what they will enter into the field. I mean, I could put default information in there like "Enter lot number here", but I have no idea what the lot number will be until they type it in...if you get what I mean....
Well you have to know at some point how many blank fields you want to display.. so just make sure you intialize your String[] with that size and then when you display the values they'll just be blank (which is what I think you want). I'm guessing the problem you are running into is you aren't intializing the size of the array to at least a number you are compfortable with.
I am trying to let the user enter information about a lot of slides that they are using, but they may be using several lots of slides and the number of lots will change every time they use the application...thus I want present a page that has a field for entering information for one lot...then I have a "add another lot" button that they can click that will allow them to enter the information for a second lot, but they should still be able to see the information they entered for the first lot, thus they will see two textfields...actually there are corresponding textareas for each textfield as well, but assuming I can get the textfield to work, I can follow suit with the textarea. In fact, they should be able to keep clicking "add new lot" without filling anything out until the end if they like...
This should work fine, but I think you might want to use type ArrayList. It might get a bit tricky working with arrays for this. Actually I take that back, I think using a String[] should still be fine... when they click on the "add new" you'll just do...
<c:forEach items="${yourForm.slideInfo}" var="info"> <html:text property="slideInfo" value="${info}"/> </c:forEach> <html:text property="slideInfo" value=""/>
I'm not 'exactly' sure how the above would work, and it would get a bit tricky if they submitted the form and didn't enter anything for the last value. What you'd have to do is check for that last index value and see it was empty and if it was you might want to remove it from the String[] (again, since you are going to be working with adding and removing stuff from an array, it might be easier working with the List APIs).
-- Rick
--------------------------------------------------------------------- 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]