struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mathew, Manoj" <Mathew.Ma...@principal.com>
Subject RE: ArrayList and DynaActionForm--need help very badly
Date Thu, 29 Apr 2004 18:44:25 GMT
Rishar

I still get the same and agian nameList = null

 [Servlet Error]-[BeanUtils.populate]: java.lang.IndexOutOfBoundsException: Index: 4, Size:
0
	at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:145)

Thank-you,
Manoj Mathew
GIS-Systems
(515-362-0539)


-----Original Message-----
From: Richard Yee [mailto:ryee86@yahoo.com]
Sent: Thursday, April 29, 2004 1:30 PM
To: Struts Users Mailing List
Subject: RE: ArrayList and DynaActionForm--need help very badly


Mathew,
Okay, forget about my previous email. Try this
instead. I didn't look at your code that closely
before.

 		List mm = new ArrayList();
 		List nameList = ListUtils.lazyList(mm, new
Factory() {
 			public Object create() {
 				return new String();
 			}
 		});
 		set("friendName", nameList);

Regards,

Richard


1) define the  the 
--- "Mathew, Manoj" <Mathew.Manoj@principal.com>
wrote:
> Richard 
>  when i use that wasy i get this error
> The following exception was logged
> java.lang.NullPointerException: The type for
> property friendName is invalid
> 	at
>
org.apache.struts.action.DynaActionForm.set(DynaActionForm.java:414)
> 
> struts config
> 
> <form-bean name="mytestform"
> type="org.apache.struts.action.DynaActionForm">
> 			<form-property name="friendName"
>
type="org.apache.commons.collections.ListUtils.LazyList"
> />
> 
> Thank-you,
> Manoj Mathew
> GIS-Systems
> (515-362-0539)
> 
> 
> -----Original Message-----
> From: Richard Yee [mailto:ryee86@yahoo.com]
> Sent: Thursday, April 29, 2004 12:06 PM
> To: Struts Users Mailing List
> Subject: RE: ArrayList and DynaActionForm--need help
> very badly
> 
> 
> Mathew,
> I think you are mixing the instructions that
> everyone
> has given you. If you use the LazyList as your
> form-property type in your form-bean, then you don't
> need to put this code,
> > 		List mm = new ArrayList();
> > 		List nameList = ListUtils.lazyList(mm, new
> > Factory() {
> > 			public Object create() {
> > 				return "fakeName";
> > 			}
> > 		});
> > 		set("friendName", nameList);
> 
> in your reset() method. In fact, you don't have to
> put
> any code that initializes your list because the
> LazyList takes care of that for you.
> 
> In the solution I proposed in my previous emails, I
> told you to put the code in the reset method only
> when
> you are using the plain ArrayList or a simple array.
> This code is necessary to prevent the index out of
> bounds exception when you use these types with
> indexed
> properties.
> 
> 
> Regards,
> 
> Richard
> --- "Mathew, Manoj" <Mathew.Manoj@principal.com>
> wrote:
> > Let me explain in detail
> > 
> > I have a open action which just populate the
> > list..and forwarded to my jsp
> > 
> > public class MyTestOpenAction extends Action {
> > 	public ActionForward execute(ActionMapping
> mapping,
> > ActionForm frm,
> > javax.servlet.http.HttpServletRequest request,
> > javax.servlet.http.HttpServletResponse response)
> > throws Exception {
> > 
> > 		myTestForm form = (myTestForm) frm;
> >         form.set("myName","Manoj Mathew");
> > 		form.set("friendName", getMyList());
> > 		return mapping.findForward("success");
> > 	}
> > 
> > 	private List getMyList() {
> > 
> > 		List myList = new ArrayList();
> > 		myList.add(0, "Jimmy");
> > 		myList.add(1, "Tom");
> > 		myList.add(2, "Jack");
> >         myList.add(3, "Jack2");
> >         myList.add(4, "Jack3");
> > 		return myList;
> > 	}
> > 
> > }
> > 
> > and my jsp looks like this
> > 
> > 
> > <html:form method="post"
> > action="mytestjsppostaction.do">
> > <Table>
> > 	<TR><TD><font color="red" face="bold">My Friend's
> > List</font></TD></TR>
> > 	<TR><TD><html:text property="myName"
> maxlength="64"
> > size="50"/></td></TR>
> > <% for(int i=0; i<5; i++){ %>
> > <% String name1 = "friendName[" + i+ "]";%>
> > 	<tr>
> > 		<td> My Friend <%= i %></td>
> > 		<td><html:text property="<%=name1%>"
> maxlength="6"
> > size="6" /></TD>
> > 	</tr>
> > <% } %>
> > <tr><td><html:submit property="censusSubmit"
> > value="Submit" /> </td></tr>
> > </table>
> > </html:form>
> > 
> > and struts config 
> > <form-bean name="mytestform"
> >
>
type="com.principal.group.acquire.proposal.ui.benefits.myTestForm">
> > 			<form-property name="friendName"
> > type="java.util.List" />
> > 			<form-property name="myName"
> > type="java.lang.String" />
> > 		</form-bean>
> > 
> > 
> > so the data populated  by the open action is shown
> > in the jsp. But when i submit the form.the control
> > goes to my dynaActionform
> > 
> > public class myTestForm extends DynaActionForm {
> > 
> > 	public void reset(ActionMapping mapping,
> > HttpServletRequest request) {
> > 
> > 		List mm = new ArrayList();
> > 		List nameList = ListUtils.lazyList(mm, new
> > Factory() {
> > 			public Object create() {
> > 				return "fakeName";
> > 			}
> > 		});
> > 		set("friendName", nameList);
> > 	}
> > }
> > 
> > and since nameList is null, it's throwing array
> > indexout ofBond.before going to the form action.
> > E SRVE0026E: [Servlet Error]-[BeanUtils.populate]:
> > java.lang.IndexOutOfBoundsException: Index: 4,
> Size:
> > 0
> > 	at
> > java.util.ArrayList.RangeCheck(ArrayList.java:511)
> > 	at java.util.ArrayList.set(ArrayList.java:343)
> > 	at
> >
>
org.apache.commons.collections.ListUtils$LazyList.set(Unknown
> > Source)
> > 	at
> >
>
org.apache.struts.action.DynaActionForm.set(DynaActionForm.java:460)
> > 	at
> >
>
org.apache.commons.beanutils.PropertyUtils.setIndexedProperty(PropertyUtils.java:1414)
> > 
> > Thank-you,
> > Manoj Mathew
> > 
> > -----Original Message-----
> > From: Hubert Rabago [mailto:jakartauser@yahoo.com]
> > Sent: Thursday, April 29, 2004 11:23 AM
> > To: Struts Users Mailing List
> > Subject: RE: ArrayList and DynaActionForm--need
> help
> > very badly
> > 
> > 
> > From the lazyList() javadoc:
> > 
> > "When the index passed to the returned list's get
> > method is greater than the
> > list's size, then the factory will be used to
> create
> > a new object and that
> > object will be inserted at that index."
> > 
> > So yes, the list is empty if what you do is check
> > the lists' size.  If you
> > actually access it with an index, then you should
> > get your fake name.
> > 
> > --- "Mathew, Manoj" <Mathew.Manoj@principal.com>
> > wrote:
> 
=== message truncated ===



	
		
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs  
http://hotjobs.sweepstakes.yahoo.com/careermakeover 

---------------------------------------------------------------------
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


Mime
View raw message