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 16:35:47 GMT
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:
> man  struk again
> 
> List nameList = ListUtils.lazyList(new ArrayList(), new Factory() {
> 			public Object create() {
> 				return "fakeName";
> 			}
> 		});
> 		set("friendName", nameList);
> 	}
> 
> nameList is null here.
> My list has a list of String objects and my intention was when ever this
> one is called , add "fakeName" as the list element.
> but the list is empty..
> 
> Thank-you,
> Manoj Mathew
> 
> 
> 
> -----Original Message-----
> From: Mathew, Manoj 
> Sent: Thursday, April 29, 2004 11:00 AM
> To: Struts Users Mailing List
> Subject: RE: ArrayList and DynaActionForm--need help very badly
> 
> 
> that works..
> 
> thanks a lot Hubert.
> 
> Thank-you,
> Manoj Mathew
> 
> 
> -----Original Message-----
> From: Hubert Rabago [mailto:jakartauser@yahoo.com]
> Sent: Thursday, April 29, 2004 10:40 AM
> To: Struts Users Mailing List
> Subject: RE: ArrayList and DynaActionForm--need help very badly
> 
> 
> Try using
> <form-property name="friendName" type="java.util.List" />
> 
> --- "Mathew, Manoj" <Mathew.Manoj@principal.com> wrote:
> > Just one more question guys
> > 
> > I am trying to implement this and getting this error.
> > 
> > Cannot assign value of type
> > 'org.apache.commons.collections.ListUtils$LazyList' to property
> > 'friendName' of type 'java.util.ArrayList']:
> > org.apache.commons.beanutils.ConversionException: Cannot assign value of
> > type 'org.apache.commons.collections.ListUtils$LazyList' to property
> > 'friendName' of type 'java.util.ArrayList'
> > 
> > my strutsconfig.xml entry
> > 
> > <form-property name="friendName" type="java.util.ArrayList" />
> > 
> > my form
> > 
> > public void reset(ActionMapping mapping, HttpServletRequest request) {
> > 		List nameList = ListUtils.lazyList(new ArrayList(), new Factory() {
> > 			public Object create() {
> > 				return "fakeName";
> > 			}
> > 		});
> > 		set("friendName", nameList);
> > 	}
> > 
> > 
> > so type List and Lazylist are not compatible?
> > Should i declare the slement also as lazyList?
> > In that case how will i acceess thi in my jsp?
> > will   friendName[" + i+ "]  work?????
> > 
> > 
> > Thank-you,
> > Manoj Mathew
> > 
> 
> 
> 
> 	
> 		
> __________________________________
> 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
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 



	
		
__________________________________
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