You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Adam K <ad...@gmail.com> on 2006/10/19 18:14:49 UTC

Textfield problem with pulling value out.

Hi all I have been working on this probelm for the past couple of days, and
don't seem to be making any progress on it.  I am fairly certain it is a
problem with my understanding of struts, and as such it makes it quite
difficult for me to solve the problem myself.
I am trying to use a textfield and pull values from it.  The following
explains the scenario.  User clicks on a page, page loads with a form that
has a textfield.  User enters search criteria and submits form.  This works
fine.  Page returns with the search form and textfield, as well as a second
form that displays the results of the search.  This also works fine.  The
user then goes through the results filling in numbers for each result
indicating how many of each they would like to order and then submit the
form.  This is where the problem results.  I end up gettting an error from
the page anytime I submit the form where there is 1 or more results.
Submitting with no results works fine and the page loads correctly.
Submitting with 1 result errors out with

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

Submitting with 10 results errors out with:
java.lang.IndexOutOfBoundsException: Index: 2, Size: 0

Submitting with 100 results errors with :
java.lang.IndexOutOfBoundsException: Index: 6, Size: 0

Submitting with 200 results errors with :
java.lang.IndexOutOfBoundsException: Index: 155, Size: 0

The number seems to be random (I am guessing it is how far into the
form it gets before the error is encountered)

Any help on this would be much appreciated.
I am including all the information that I believe to be important but
would have no problem including more.

In the jsp form there is:

<html:form action="/skuSearch" method="post" >
	<center>
		<table width="400" border="1" align="center" cellpadding="0" cellspacing="0">
			<tr>
				<td>
					<table border="0" cellspacing="1" cellpadding="1" width="100%" >
			  		   <tr align="center">
						      <td><html:text property="searchString" size="30"
maxlength="30"/></td>
						      <td><html:submit>Search</html:submit></td>
					   </tr>
					   <tr><td colspan="2"></td></tr>
					</table>
				</td>
			</tr>
		</table>
	</center>
</html:form>


<html:form action="/searchResults" method="post" >
<center><p><html:submit>Add To Order</html:submit></p></center>
<table align ="center" width="90%" border=1>
	<tr>
		<td>	Product			</td>
		<td>	Product Desc		</td>
		<td>	Quantity		</td>
	</tr>

<logic:notEmpty name="SkuSearchForm" property="results">
	<logic:iterate name="SkuSearchForm" property="results" id="results">
	<tr>
		<td>	<bean:write name="results" property="product" />			</td>
		<td>	<bean:write name="results" property="description" /> 			</td>
		<td>	<html:text name="results" property="numProducts" indexed="true" />	</td>
	</tr>
	</logic:iterate>
</logic:notEmpty>

<logic:empty name="SkuSearchForm" property="results">
	  	<tr><td colspan="3" align="center">NO RESULTS</td></tr>
</logic:empty>
</table>
</html:form>

In the action (this action is only for the search results):
	public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws
Exception
	{
		SkuSearchForm skuform = (SkuSearchForm) form;
		HttpSession session = request.getSession();
		User user = new User();
		Order order = new Order();
		ArrayList products = new ArrayList();
		
		ArrayList results = new ArrayList();
		user = (User)session.getAttribute("User");
		order = user.getOrder(user.getCurrOrder());
		products = order.getProducts();
		int number = 0;
		int count = 0;
	
		Iterator iter = results.iterator();
//there is nothing happening in here as there is no results for some reason.
		while(iter.hasNext())
		{
			Product p = (Product) iter.next();
			if(p.getNumProducts() != 0 )
			{
				products.add(p);
			}
				
			count++;								
		}
			{
				count = 1;
				Product p = new Product("TestProd " + count, "TestDesc"+count + "
" +count, 10, new BigDecimal("101.0"));
				products.add(p);
				results.add(p);
				count++;									
			}

		order.setProducts(products);
	    	order.setOrderId("ID12");
		user.changeOrder(order, "ID12");
	    	skuform.setResults(results);
		
		return mapping.findForward("success");		
	}	

In the form (The methods I thought were appropriate):

	public void setResults(ArrayList results)
	{
	   this.results=results;
	}

	public ArrayList getResults()
	{
	   return this.results;
	}
	
	public Product getResult(int index)
	{
		if(this.results == null)
		{
			this.results = new ArrayList();
		}
		while(index>= this.results.size())
		{
			this.results.add(new Product());
		}
		
		return (Product)results.get(index);
	}



Thanks so much in advance for your time on this matter.

Adam

Re: Textfield problem with pulling value out.

Posted by Adam K <ad...@gmail.com>.
I managed to get the problem working, unfortunately that fix is by doing
something that is against best practices (if I understand them correctly).
To get this to work what I ended up doing was pulling the results from the
search and putting that in the reset of the resultsAction.  I am pretty
certain your question about the setting the value on the set and not the get
hit the nail on the head.  I will work on the suggestions that you made and
see what progress I can make.

Thanks again so much for all the time and effort.


On 10/19/06, Adam K <ad...@gmail.com> wrote:
>
> It's more likely that I don't understand.  This is my first struts project
> and I am learning as I go.
>
>
> Here is all of the getters/setters that I have so far.  It is quite
> possible that I am missing some, but the previous page that I created that
> works used only those listed, and it works fine.  The main difference being
> that the working one only has 1 form on the page, and that I use the reset
> method to pre-populate the page (which I have since learned is bad, but I
> haven't gotten back to fixing it).
>
>    public int getNumProducts() {
>         return numProducts;
>     }
>
>     public void setNumProducts(int numProducts)
>     {
>         this.numProducts = numProducts;
>     }
>
>
>     public int getNumProducts(int index)
>     {
>         if(this.results== null)
>         {
>             this.results = new ArrayList();
>         }
>         while(index >= this.results.size() +1)
>         {
>             this.results.add(new Product());
>         }
>
>         Product p = (Product) results.get(index);
>         return p.getNumProducts();
>     }
>
>
> On 10/19/06, Puneet Lakhina <pu...@gmail.com> wrote:
> >
> > On 10/20/06, Adam K <ad...@gmail.com> wrote:
> > >
> > > Getter and setter methods for ?  (Sorry if it should be obvious but I
> > want
> > > to clarify as it isn't obvious to me)
> >
> >
> > for numProducts indexed property. And i dont understand why are you
> > populating blank values in the getter methods..I mean you should be
> > doing
> > that in your setter methods..something like
> >
> > public void setNumProducts(int index,String val) {
> > while(index <= results.size()) {
> > results.add(new Product());
> > }
> > Product p = (Product)results.get(index);
> > p.setNumProducts(val);
> > }
> > maybe i dont understnad the context of your problem properly, but this
> > what
> > i do with indexed properties.
> >
> > As far the error message here is what I recieve:
> > >
> > > javax.servlet.ServletException: BeanUtils.populate
> > >         org.apache.struts.util.RequestUtils.populate(RequestUtils.java
> > > :495)
> > >         org.apache.struts.action.RequestProcessor.processPopulate(
> > > RequestProcessor.java:816)
> > >         org.apache.struts.action.RequestProcessor.process(
> > > RequestProcessor.java :203)
> > >         org.apache.struts.action.ActionServlet.process(
> > ActionServlet.java
> > > :1196)
> > >         org.apache.struts.action.ActionServlet.doPost(
> > ActionServlet.java
> > > :432)
> > >         javax.servlet.http.HttpServlet.service (HttpServlet.java:727)
> > >         javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
> > >         com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
> > >         com.sun.enterprise.web.VirtualServerPipeline.invoke (
> > > VirtualServerPipeline.java:120)
> > >         org.apache.coyote.tomcat5.CoyoteAdapter.service(
> > CoyoteAdapter.java
> > > :231)
> > >
> > > com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter (
> > > ProcessorTask.java:667)
> > >
> > >
> > com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked
> > (
> > > ProcessorTask.java:574)
> > >         com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(
> > > ProcessorTask.java:844)
> > >
> > > com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask
> > (
> > > ReadTask.java:287)
> > >         com.sun.enterprise.web.connector.grizzly.ReadTask.doTask (
> > > ReadTask.java:212)
> > >         com.sun.enterprise.web.connector.grizzly.TaskBase.run(
> > > TaskBase.java:252)
> > >         com.sun.enterprise.web.connector.grizzly.WorkerThread.run(
> > > WorkerThread.java :75)
> > >
> > > *root cause*
> > >
> > > java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
> > >         java.util.ArrayList.RangeCheck(ArrayList.java:546)
> > >         java.util.ArrayList.get(ArrayList.java :321)
> > >
> > org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(
> > > PropertyUtilsBean.java:433)
> > >
> > org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(
> > > PropertyUtilsBean.java :340)
> > >
> > org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(
> > > PropertyUtilsBean.java:684)
> > >         org.apache.commons.beanutils.PropertyUtilsBean.getProperty(
> > > PropertyUtilsBean.java :715)
> > >         org.apache.commons.beanutils.BeanUtilsBean.setProperty(
> > > BeanUtilsBean.java:884)
> > >         org.apache.commons.beanutils.BeanUtilsBean.populate(
> > > BeanUtilsBean.java:811)
> > >         org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java
> > > :298)
> > >         org.apache.struts.util.RequestUtils.populate(RequestUtils.java
> > > :493)
> > >         org.apache.struts.action.RequestProcessor.processPopulate (
> > > RequestProcessor.java:816)
> > >         org.apache.struts.action.RequestProcessor.process(
> > > RequestProcessor.java:203)
> > >         org.apache.struts.action.ActionServlet.process(
> > ActionServlet.java
> > > :1196)
> > >         org.apache.struts.action.ActionServlet.doPost(
> > ActionServlet.java
> > > :432)
> > >         javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
> > >         javax.servlet.http.HttpServlet.service (HttpServlet.java:820)
> > >         com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
> > >         com.sun.enterprise.web.VirtualServerPipeline.invoke(
> > > VirtualServerPipeline.java:120)
> > >         org.apache.coyote.tomcat5.CoyoteAdapter.service(
> > CoyoteAdapter.java
> > > :231)
> > >
> > > com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(
> > > ProcessorTask.java:667)
> > >
> > >
> > com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(
> > > ProcessorTask.java:574)
> > >         com.sun.enterprise.web.connector.grizzly.ProcessorTask.process
> > (
> > > ProcessorTask.java:844)
> > >
> > > com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(
> > > ReadTask.java:287)
> > >         com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(
> > > ReadTask.java:212)
> > >         com.sun.enterprise.web.connector.grizzly.TaskBase.run(
> > > TaskBase.java :252)
> > >         com.sun.enterprise.web.connector.grizzly.WorkerThread.run(
> > > WorkerThread.java:75)
> > >
> > >
> >
> >
> > --
> > Puneet
> >
> >
>

Re: Textfield problem with pulling value out.

Posted by Adam K <ad...@gmail.com>.
It's more likely that I don't understand.  This is my first struts project
and I am learning as I go.


Here is all of the getters/setters that I have so far.  It is quite possible
that I am missing some, but the previous page that I created that works used
only those listed, and it works fine.  The main difference being that the
working one only has 1 form on the page, and that I use the reset method to
pre-populate the page (which I have since learned is bad, but I haven't
gotten back to fixing it).

   public int getNumProducts() {
        return numProducts;
    }

    public void setNumProducts(int numProducts)
    {
        this.numProducts = numProducts;
    }


    public int getNumProducts(int index)
    {
        if(this.results== null)
        {
            this.results = new ArrayList();
        }
        while(index >= this.results.size() +1)
        {
            this.results.add(new Product());
        }

        Product p = (Product) results.get(index);
        return p.getNumProducts();
    }


On 10/19/06, Puneet Lakhina <pu...@gmail.com> wrote:
>
> On 10/20/06, Adam K <ad...@gmail.com> wrote:
> >
> > Getter and setter methods for ?  (Sorry if it should be obvious but I
> want
> > to clarify as it isn't obvious to me)
>
>
> for numProducts indexed property. And i dont understand why are you
> populating blank values in the getter methods..I mean you should be doing
> that in your setter methods..something like
>
> public void setNumProducts(int index,String val) {
> while(index <= results.size()) {
> results.add(new Product());
> }
> Product p = (Product)results.get(index);
> p.setNumProducts(val);
> }
> maybe i dont understnad the context of your problem properly, but this
> what
> i do with indexed properties.
>
> As far the error message here is what I recieve:
> >
> > javax.servlet.ServletException: BeanUtils.populate
> >         org.apache.struts.util.RequestUtils.populate(RequestUtils.java
> > :495)
> >         org.apache.struts.action.RequestProcessor.processPopulate(
> > RequestProcessor.java:816)
> >         org.apache.struts.action.RequestProcessor.process(
> > RequestProcessor.java:203)
> >         org.apache.struts.action.ActionServlet.process(
> ActionServlet.java
> > :1196)
> >         org.apache.struts.action.ActionServlet.doPost(ActionServlet.java
> > :432)
> >         javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
> >         javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
> >         com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
> >         com.sun.enterprise.web.VirtualServerPipeline.invoke(
> > VirtualServerPipeline.java:120)
> >         org.apache.coyote.tomcat5.CoyoteAdapter.service(
> CoyoteAdapter.java
> > :231)
> >
> > com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(
> > ProcessorTask.java:667)
> >
> > com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked
> (
> > ProcessorTask.java:574)
> >         com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(
> > ProcessorTask.java:844)
> >
> > com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(
> > ReadTask.java:287)
> >         com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(
> > ReadTask.java:212)
> >         com.sun.enterprise.web.connector.grizzly.TaskBase.run(
> > TaskBase.java:252)
> >         com.sun.enterprise.web.connector.grizzly.WorkerThread.run(
> > WorkerThread.java:75)
> >
> > *root cause*
> >
> > java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
> >         java.util.ArrayList.RangeCheck(ArrayList.java:546)
> >         java.util.ArrayList.get(ArrayList.java:321)
> >
> org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(
> > PropertyUtilsBean.java:433)
> >
> org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(
> > PropertyUtilsBean.java:340)
> >         org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty
> (
> > PropertyUtilsBean.java:684)
> >         org.apache.commons.beanutils.PropertyUtilsBean.getProperty(
> > PropertyUtilsBean.java:715)
> >         org.apache.commons.beanutils.BeanUtilsBean.setProperty(
> > BeanUtilsBean.java:884)
> >         org.apache.commons.beanutils.BeanUtilsBean.populate(
> > BeanUtilsBean.java:811)
> >         org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java
> > :298)
> >         org.apache.struts.util.RequestUtils.populate(RequestUtils.java
> > :493)
> >         org.apache.struts.action.RequestProcessor.processPopulate(
> > RequestProcessor.java:816)
> >         org.apache.struts.action.RequestProcessor.process(
> > RequestProcessor.java:203)
> >         org.apache.struts.action.ActionServlet.process(
> ActionServlet.java
> > :1196)
> >         org.apache.struts.action.ActionServlet.doPost(ActionServlet.java
> > :432)
> >         javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
> >         javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
> >         com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
> >         com.sun.enterprise.web.VirtualServerPipeline.invoke(
> > VirtualServerPipeline.java:120)
> >         org.apache.coyote.tomcat5.CoyoteAdapter.service(
> CoyoteAdapter.java
> > :231)
> >
> > com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(
> > ProcessorTask.java:667)
> >
> > com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked
> (
> > ProcessorTask.java:574)
> >         com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(
> > ProcessorTask.java:844)
> >
> > com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(
> > ReadTask.java:287)
> >         com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(
> > ReadTask.java:212)
> >         com.sun.enterprise.web.connector.grizzly.TaskBase.run(
> > TaskBase.java:252)
> >         com.sun.enterprise.web.connector.grizzly.WorkerThread.run(
> > WorkerThread.java:75)
> >
> >
>
>
> --
> Puneet
>
>

Re: Textfield problem with pulling value out.

Posted by Puneet Lakhina <pu...@gmail.com>.
On 10/20/06, Adam K <ad...@gmail.com> wrote:
>
> Getter and setter methods for ?  (Sorry if it should be obvious but I want
> to clarify as it isn't obvious to me)


for numProducts indexed property. And i dont understand why are you
populating blank values in the getter methods..I mean you should be doing
that in your setter methods..something like

public void setNumProducts(int index,String val) {
while(index <= results.size()) {
results.add(new Product());
}
Product p = (Product)results.get(index);
p.setNumProducts(val);
}
maybe i dont understnad the context of your problem properly, but this what
i do with indexed properties.

As far the error message here is what I recieve:
>
> javax.servlet.ServletException: BeanUtils.populate
>         org.apache.struts.util.RequestUtils.populate(RequestUtils.java
> :495)
>         org.apache.struts.action.RequestProcessor.processPopulate(
> RequestProcessor.java:816)
>         org.apache.struts.action.RequestProcessor.process(
> RequestProcessor.java:203)
>         org.apache.struts.action.ActionServlet.process(ActionServlet.java
> :1196)
>         org.apache.struts.action.ActionServlet.doPost(ActionServlet.java
> :432)
>         javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
>         javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
>         com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
>         com.sun.enterprise.web.VirtualServerPipeline.invoke(
> VirtualServerPipeline.java:120)
>         org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java
> :231)
>
> com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(
> ProcessorTask.java:667)
>
> com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(
> ProcessorTask.java:574)
>         com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(
> ProcessorTask.java:844)
>
> com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(
> ReadTask.java:287)
>         com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(
> ReadTask.java:212)
>         com.sun.enterprise.web.connector.grizzly.TaskBase.run(
> TaskBase.java:252)
>         com.sun.enterprise.web.connector.grizzly.WorkerThread.run(
> WorkerThread.java:75)
>
> *root cause*
>
> java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
>         java.util.ArrayList.RangeCheck(ArrayList.java:546)
>         java.util.ArrayList.get(ArrayList.java:321)
>         org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(
> PropertyUtilsBean.java:433)
>         org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(
> PropertyUtilsBean.java:340)
>         org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(
> PropertyUtilsBean.java:684)
>         org.apache.commons.beanutils.PropertyUtilsBean.getProperty(
> PropertyUtilsBean.java:715)
>         org.apache.commons.beanutils.BeanUtilsBean.setProperty(
> BeanUtilsBean.java:884)
>         org.apache.commons.beanutils.BeanUtilsBean.populate(
> BeanUtilsBean.java:811)
>         org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java
> :298)
>         org.apache.struts.util.RequestUtils.populate(RequestUtils.java
> :493)
>         org.apache.struts.action.RequestProcessor.processPopulate(
> RequestProcessor.java:816)
>         org.apache.struts.action.RequestProcessor.process(
> RequestProcessor.java:203)
>         org.apache.struts.action.ActionServlet.process(ActionServlet.java
> :1196)
>         org.apache.struts.action.ActionServlet.doPost(ActionServlet.java
> :432)
>         javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
>         javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
>         com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
>         com.sun.enterprise.web.VirtualServerPipeline.invoke(
> VirtualServerPipeline.java:120)
>         org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java
> :231)
>
> com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(
> ProcessorTask.java:667)
>
> com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(
> ProcessorTask.java:574)
>         com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(
> ProcessorTask.java:844)
>
> com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(
> ReadTask.java:287)
>         com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(
> ReadTask.java:212)
>         com.sun.enterprise.web.connector.grizzly.TaskBase.run(
> TaskBase.java:252)
>         com.sun.enterprise.web.connector.grizzly.WorkerThread.run(
> WorkerThread.java:75)
>
>


-- 
Puneet

Re: Textfield problem with pulling value out.

Posted by Adam K <ad...@gmail.com>.
Getter and setter methods for ?  (Sorry if it should be obvious but I want
to clarify as it isn't obvious to me)

As far the error message here is what I recieve:

javax.servlet.ServletException: BeanUtils.populate
	org.apache.struts.util.RequestUtils.populate(RequestUtils.java:495)
	org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:816)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
	org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
	com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
	com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
	org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:231)
	com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
	com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
	com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
	com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
	com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
	com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
	com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)

*root cause*

java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
	java.util.ArrayList.RangeCheck(ArrayList.java:546)
	java.util.ArrayList.get(ArrayList.java:321)
	org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(PropertyUtilsBean.java:433)
	org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(PropertyUtilsBean.java:340)
	org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:684)
	org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:715)
	org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:884)
	org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811)
	org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)
	org.apache.struts.util.RequestUtils.populate(RequestUtils.java:493)
	org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:816)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
	org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
	com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
	com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
	org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:231)
	com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
	com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
	com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
	com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
	com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
	com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
	com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)

Re: Textfield problem with pulling value out.

Posted by Puneet Lakhina <pu...@gmail.com>.
On 10/19/06, Adam K <ad...@gmail.com> wrote:
>
> Here are the 2 get methods that I have.
>
> thanks again for all the help.
>
>
>     public int getNumProducts() {
>         return numProducts;
>     }
>
>
>     public int getNumProducts(int index)
>     {
>         if(this.results== null)
>         {
>             this.results = new ArrayList();
>         }
>         while(index >= this.results.size())
>         {
>             this.results.add(new Product());
>         }
>
>         Product p = (Product) results.get(index);
>         return p.getNumProducts();
>     }


Sorry i actually meant post your getter and setter methods..coz the
setNumProducts is what is probaly causing the problem..and ya post the full
exception trace.

On 10/19/06, Puneet Lakhina <pu...@gmail.com> wrote:
> >
> > On 10/19/06, Adam K <ad...@gmail.com> wrote:
> > >
> > > Hi all I have been working on this probelm for the past couple of
> days,
> > > and
> > > don't seem to be making any progress on it.  I am fairly certain it is
> a
> > > problem with my understanding of struts, and as such it makes it quite
> > > difficult for me to solve the problem myself.
> > > I am trying to use a textfield and pull values from it.  The following
> > > explains the scenario.  User clicks on a page, page loads with a form
> > that
> > > has a textfield.  User enters search criteria and submits form.  This
> > > works
> > > fine.  Page returns with the search form and textfield, as well as a
> > > second
> > > form that displays the results of the search.  This also works
> > fine.  The
> > > user then goes through the results filling in numbers for each result
> > > indicating how many of each they would like to order and then submit
> the
> > > form.  This is where the problem results.  I end up gettting an error
> > from
> > > the page anytime I submit the form where there is 1 or more results.
> > > Submitting with no results works fine and the page loads correctly.
> > > Submitting with 1 result errors out with
> > >
> > > java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
> > >
> > > Submitting with 10 results errors out with:
> > > java.lang.IndexOutOfBoundsException: Index: 2, Size: 0
> > >
> > > Submitting with 100 results errors with :
> > > java.lang.IndexOutOfBoundsException: Index: 6, Size: 0
> > >
> > > Submitting with 200 results errors with :
> > > java.lang.IndexOutOfBoundsException: Index: 155, Size: 0
> > >
> > > The number seems to be random (I am guessing it is how far into the
> > > form it gets before the error is encountered)
> > >
> > > Any help on this would be much appreciated.
> > > I am including all the information that I believe to be important but
> > > would have no problem including more.
> > >
> > > In the jsp form there is:
> > >
> > > <html:form action="/skuSearch" method="post" >
> > >         <center>
> > >                 <table width="400" border="1" align="center"
> > > cellpadding="0" cellspacing="0">
> > >                         <tr>
> > >                                 <td>
> > >                                         <table border="0"
> > cellspacing="1"
> > > cellpadding="1" width="100%" >
> > >                                            <tr align="center">
> > >                                                       <td><html:text
> > > property="searchString" size="30"
> > > maxlength="30"/></td>
> > >
> > >
> > <td><html:submit>Search</html:submit></td>
> > >                                            </tr>
> > >                                            <tr><td
> > colspan="2"></td></tr>
> > >                                         </table>
> > >                                 </td>
> > >                         </tr>
> > >                 </table>
> > >         </center>
> > > </html:form>
> > >
> > >
> > > <html:form action="/searchResults" method="post" >
> > > <center><p><html:submit>Add To Order</html:submit></p></center>
> > > <table align ="center" width="90%" border=1>
> > >         <tr>
> > >                 <td>    Product                 </td>
> > >                 <td>    Product Desc            </td>
> > >                 <td>    Quantity                </td>
> > >         </tr>
> > >
> > > <logic:notEmpty name="SkuSearchForm" property="results">
> > >         <logic:iterate name="SkuSearchForm" property="results"
> > > id="results">
> > >         <tr>
> > >                 <td>    <bean:write name="results" property="product"
> > > />                        </td>
> > >                 <td>    <bean:write name="results"
> > property="description"
> > > />                    </td>
> > >                 <td>    <html:text name="results"
> property="numProducts"
> > > indexed="true" />
> >
> >
> > post the getter method for the numProducts. that might be causing the
> > problem.
> >
> >      </td>
> > >         </tr>
> > >         </logic:iterate>
> > > </logic:notEmpty>
> > >
> > > <logic:empty name="SkuSearchForm" property="results">
> > >                 <tr><td colspan="3" align="center">NO
> RESULTS</td></tr>
> > > </logic:empty>
> > > </table>
> > > </html:form>
> > >
> > > In the action (this action is only for the search results):
> > >         public ActionForward execute(ActionMapping mapping, ActionForm
> > > form,
> > > HttpServletRequest request, HttpServletResponse response) throws
> > > Exception
> > >         {
> > >                 SkuSearchForm skuform = (SkuSearchForm) form;
> > >                 HttpSession session = request.getSession();
> > >                 User user = new User();
> > >                 Order order = new Order();
> > >                 ArrayList products = new ArrayList();
> > >
> > >                 ArrayList results = new ArrayList();
> > >                 user = (User)session.getAttribute("User");
> > >                 order = user.getOrder(user.getCurrOrder());
> > >                 products = order.getProducts();
> > >                 int number = 0;
> > >                 int count = 0;
> > >
> > >                 Iterator iter = results.iterator();
> > > //there is nothing happening in here as there is no results for some
> > > reason.
> > >                 while(iter.hasNext())
> > >                 {
> > >                         Product p = (Product) iter.next();
> > >                         if(p.getNumProducts() != 0 )
> > >                         {
> > >                                 products.add(p);
> > >                         }
> > >
> > >                         count++;
> > >                 }
> > >                         {
> > >                                 count = 1;
> > >                                 Product p = new Product("TestProd " +
> > > count, "TestDesc"+count + "
> > > " +count, 10, new BigDecimal("101.0"));
> > >                                 products.add(p);
> > >                                 results.add(p);
> > >                                 count++;
> > >                         }
> > >
> > >                 order.setProducts(products);
> > >                 order.setOrderId("ID12");
> > >                 user.changeOrder(order, "ID12");
> > >                 skuform.setResults(results);
> > >
> > >                 return mapping.findForward("success");
> > >         }
> > >
> > > In the form (The methods I thought were appropriate):
> > >
> > >         public void setResults(ArrayList results)
> > >         {
> > >            this.results=results;
> > >         }
> > >
> > >         public ArrayList getResults()
> > >         {
> > >            return this.results;
> > >         }
> > >
> > >         public Product getResult(int index)
> > >         {
> > >                 if(this.results == null)
> > >                 {
> > >                         this.results = new ArrayList();
> > >                 }
> > >                 while(index>= this.results.size())
> > >                 {
> > >                         this.results.add(new Product());
> > >                 }
> > >
> > >                 return (Product)results.get(index);
> > >         }
> > >
> > >
> > >
> > > Thanks so much in advance for your time on this matter.
> > >
> > > Adam
> > >
> > >
> >
> >
> > --
> > Puneet
> >
> >
>
>


-- 
Puneet

Re: Textfield problem with pulling value out.

Posted by Adam K <ad...@gmail.com>.
One other thing I just realized that I should include is the fact that all
of my forms are request based, which doesn't allow me to include the form
information from one to the next, so to get around that (for more testing) I
have included the array in a Session variable so that I can pull it out in
the second action.

Again thanks for all thoughts/ideas/suggestions

On 10/19/06, Adam K <ad...@gmail.com> wrote:
>
> If this is a bad technique I would be more than happy to change it to a
> more standard technique.  Any suggestions on how to improve my code are
> always welcome.
>
> thanks for the suggestions thus far.
> Adam
>
> On 10/19/06, Chris Pratt <thechrispratt@gmail.com > wrote:
> >
> > I don't think I've ever seen that technique before, but you have to
> > remember
> > that size() is 1 based and index (or get(index) ) is 0 based.  So when
> > someone calls getNumProducts(5), your while loop fills in indexes 0, 1,
> > 2,
> > 3, and 4 (because then index and this.results.size() are both 5), then
> > you
> > proceed to ask for results.get(5), which doesn't exist.  You should be
> > able
> > to change your while list to something like:
> >
> > while(index >= this.results.size() + 1) {
> >   this.results.add(new Product());
> > }
> >
> >   (*Chris*)
> >
> > On 10/19/06, Adam K < adamk1@gmail.com> wrote:
> > >
> > > Here are the 2 get methods that I have.
> > >
> > > thanks again for all the help.
> > >
> > >
> > >     public int getNumProducts() {
> > >         return numProducts;
> > >     }
> > >
> > >
> > >     public int getNumProducts(int index)
> > >     {
> > >         if(this.results== null)
> > >         {
> > >             this.results = new ArrayList();
> > >         }
> > >         while(index >= this.results.size())
> > >         {
> > >             this.results.add(new Product());
> > >         }
> > >
> > >         Product p = (Product) results.get(index);
> > >         return p.getNumProducts();
> > >     }
> > >
> > > On 10/19/06, Puneet Lakhina < puneet.lakhina@gmail.com> wrote:
> > > >
> > > > On 10/19/06, Adam K < adamk1@gmail.com> wrote:
> > > > >
> > > > > Hi all I have been working on this probelm for the past couple of
> > > days,
> > > > > and
> > > > > don't seem to be making any progress on it.  I am fairly certain
> > it is
> > > a
> > > > > problem with my understanding of struts, and as such it makes it
> > quite
> > > > > difficult for me to solve the problem myself.
> > > > > I am trying to use a textfield and pull values from it.  The
> > following
> > > > > explains the scenario.  User clicks on a page, page loads with a
> > form
> > > > that
> > > > > has a textfield.  User enters search criteria and submits
> > form.  This
> > > > > works
> > > > > fine.  Page returns with the search form and textfield, as well as
> > a
> > > > > second
> > > > > form that displays the results of the search.  This also works
> > > > fine.  The
> > > > > user then goes through the results filling in numbers for each
> > result
> > > > > indicating how many of each they would like to order and then
> > submit
> > > the
> > > > > form.  This is where the problem results.  I end up gettting an
> > error
> > > > from
> > > > > the page anytime I submit the form where there is 1 or more
> > results.
> > > > > Submitting with no results works fine and the page loads
> > correctly.
> > > > > Submitting with 1 result errors out with
> > > > >
> > > > > java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
> > > > >
> > > > > Submitting with 10 results errors out with:
> > > > > java.lang.IndexOutOfBoundsException: Index: 2, Size: 0
> > > > >
> > > > > Submitting with 100 results errors with :
> > > > > java.lang.IndexOutOfBoundsException: Index: 6, Size: 0
> > > > >
> > > > > Submitting with 200 results errors with :
> > > > > java.lang.IndexOutOfBoundsException: Index: 155, Size: 0
> > > > >
> > > > > The number seems to be random (I am guessing it is how far into
> > the
> > > > > form it gets before the error is encountered)
> > > > >
> > > > > Any help on this would be much appreciated.
> > > > > I am including all the information that I believe to be important
> > but
> > > > > would have no problem including more.
> > > > >
> > > > > In the jsp form there is:
> > > > >
> > > > > <html:form action="/skuSearch" method="post" >
> > > > >         <center>
> > > > >                 <table width="400" border="1" align="center"
> > > > > cellpadding="0" cellspacing="0">
> > > > >                         <tr>
> > > > >                                 <td>
> > > > >                                         <table border="0"
> > > > cellspacing="1"
> > > > > cellpadding="1" width="100%" >
> > > > >                                            <tr align="center">
> > > > >
> > <td><html:text
> > > > > property="searchString" size="30"
> > > > > maxlength="30"/></td>
> > > > >
> > > > >
> > > > <td><html:submit>Search</html:submit></td>
> > > > >                                            </tr>
> > > > >                                            <tr><td
> > > > colspan="2"></td></tr>
> > > > >                                         </table>
> > > > >                                 </td>
> > > > >                         </tr>
> > > > >                 </table>
> > > > >         </center>
> > > > > </html:form>
> > > > >
> > > > >
> > > > > <html:form action="/searchResults" method="post" >
> > > > > <center><p><html:submit>Add To Order</html:submit></p></center>
> > > > > <table align ="center" width="90%" border=1>
> > > > >         <tr>
> > > > >                 <td>    Product                 </td>
> > > > >                 <td>    Product Desc            </td>
> > > > >                 <td>    Quantity                </td>
> > > > >         </tr>
> > > > >
> > > > > <logic:notEmpty name="SkuSearchForm" property="results">
> > > > >         <logic:iterate name="SkuSearchForm" property="results"
> > > > > id="results">
> > > > >         <tr>
> > > > >                 <td>    <bean:write name="results"
> > property="product"
> > > > > />                        </td>
> > > > >                 <td>    <bean:write name="results"
> > > > property="description"
> > > > > />                    </td>
> > > > >                 <td>    <html:text name="results"
> > > property="numProducts"
> > > > > indexed="true" />
> > > >
> > > >
> > > > post the getter method for the numProducts. that might be causing
> > the
> > > > problem.
> > > >
> > > >      </td>
> > > > >         </tr>
> > > > >         </logic:iterate>
> > > > > </logic:notEmpty>
> > > > >
> > > > > <logic:empty name="SkuSearchForm" property="results">
> > > > >                 <tr><td colspan="3" align="center">NO
> > > RESULTS</td></tr>
> > > > > </logic:empty>
> > > > > </table>
> > > > > </html:form>
> > > > >
> > > > > In the action (this action is only for the search results):
> > > > >         public ActionForward execute(ActionMapping mapping,
> > ActionForm
> > > > > form,
> > > > > HttpServletRequest request, HttpServletResponse response) throws
> > > > > Exception
> > > > >         {
> > > > >                 SkuSearchForm skuform = (SkuSearchForm) form;
> > > > >                 HttpSession session = request.getSession();
> > > > >                 User user = new User();
> > > > >                 Order order = new Order();
> > > > >                 ArrayList products = new ArrayList();
> > > > >
> > > > >                 ArrayList results = new ArrayList();
> > > > >                 user = (User)session.getAttribute("User");
> > > > >                 order = user.getOrder(user.getCurrOrder());
> > > > >                 products = order.getProducts();
> > > > >                 int number = 0;
> > > > >                 int count = 0;
> > > > >
> > > > >                 Iterator iter = results.iterator();
> > > > > //there is nothing happening in here as there is no results for
> > some
> > > > > reason.
> > > > >                 while(iter.hasNext())
> > > > >                 {
> > > > >                         Product p = (Product) iter.next();
> > > > >                         if(p.getNumProducts() != 0 )
> > > > >                         {
> > > > >                                 products.add(p);
> > > > >                         }
> > > > >
> > > > >                         count++;
> > > > >                 }
> > > > >                         {
> > > > >                                 count = 1;
> > > > >                                 Product p = new Product("TestProd
> > " +
> > > > > count, "TestDesc"+count + "
> > > > > " +count, 10, new BigDecimal("101.0"));
> > > > >                                 products.add(p);
> > > > >                                 results.add(p);
> > > > >                                 count++;
> > > > >                         }
> > > > >
> > > > >                 order.setProducts(products);
> > > > >                 order.setOrderId("ID12");
> > > > >                 user.changeOrder(order, "ID12");
> > > > >                 skuform.setResults(results);
> > > > >
> > > > >                 return mapping.findForward("success");
> > > > >         }
> > > > >
> > > > > In the form (The methods I thought were appropriate):
> > > > >
> > > > >         public void setResults(ArrayList results)
> > > > >         {
> > > > >            this.results=results;
> > > > >         }
> > > > >
> > > > >         public ArrayList getResults()
> > > > >         {
> > > > >            return this.results;
> > > > >         }
> > > > >
> > > > >         public Product getResult(int index)
> > > > >         {
> > > > >                 if(this.results == null)
> > > > >                 {
> > > > >                         this.results = new ArrayList();
> > > > >                 }
> > > > >                 while(index>= this.results.size())
> > > > >                 {
> > > > >                         this.results.add(new Product());
> > > > >                 }
> > > > >
> > > > >                 return (Product)results.get(index);
> > > > >         }
> > > > >
> > > > >
> > > > >
> > > > > Thanks so much in advance for your time on this matter.
> > > > >
> > > > > Adam
> > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > > Puneet
> > > >
> > > >
> > >
> > >
> >
> >
>

Re: Textfield problem with pulling value out.

Posted by Adam K <ad...@gmail.com>.
If this is a bad technique I would be more than happy to change it to a more
standard technique.  Any suggestions on how to improve my code are always
welcome.

thanks for the suggestions thus far.
Adam

On 10/19/06, Chris Pratt <th...@gmail.com> wrote:
>
> I don't think I've ever seen that technique before, but you have to
> remember
> that size() is 1 based and index (or get(index) ) is 0 based.  So when
> someone calls getNumProducts(5), your while loop fills in indexes 0, 1, 2,
>
> 3, and 4 (because then index and this.results.size() are both 5), then you
> proceed to ask for results.get(5), which doesn't exist.  You should be
> able
> to change your while list to something like:
>
> while(index >= this.results.size() + 1) {
>   this.results.add(new Product());
> }
>
>   (*Chris*)
>
> On 10/19/06, Adam K <ad...@gmail.com> wrote:
> >
> > Here are the 2 get methods that I have.
> >
> > thanks again for all the help.
> >
> >
> >     public int getNumProducts() {
> >         return numProducts;
> >     }
> >
> >
> >     public int getNumProducts(int index)
> >     {
> >         if(this.results== null)
> >         {
> >             this.results = new ArrayList();
> >         }
> >         while(index >= this.results.size())
> >         {
> >             this.results.add(new Product());
> >         }
> >
> >         Product p = (Product) results.get(index);
> >         return p.getNumProducts();
> >     }
> >
> > On 10/19/06, Puneet Lakhina < puneet.lakhina@gmail.com> wrote:
> > >
> > > On 10/19/06, Adam K <ad...@gmail.com> wrote:
> > > >
> > > > Hi all I have been working on this probelm for the past couple of
> > days,
> > > > and
> > > > don't seem to be making any progress on it.  I am fairly certain it
> is
> > a
> > > > problem with my understanding of struts, and as such it makes it
> quite
> > > > difficult for me to solve the problem myself.
> > > > I am trying to use a textfield and pull values from it.  The
> following
> > > > explains the scenario.  User clicks on a page, page loads with a
> form
> > > that
> > > > has a textfield.  User enters search criteria and submits
> form.  This
> > > > works
> > > > fine.  Page returns with the search form and textfield, as well as a
> > > > second
> > > > form that displays the results of the search.  This also works
> > > fine.  The
> > > > user then goes through the results filling in numbers for each
> result
> > > > indicating how many of each they would like to order and then submit
>
> > the
> > > > form.  This is where the problem results.  I end up gettting an
> error
> > > from
> > > > the page anytime I submit the form where there is 1 or more results.
> > > > Submitting with no results works fine and the page loads correctly.
> > > > Submitting with 1 result errors out with
> > > >
> > > > java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
> > > >
> > > > Submitting with 10 results errors out with:
> > > > java.lang.IndexOutOfBoundsException: Index: 2, Size: 0
> > > >
> > > > Submitting with 100 results errors with :
> > > > java.lang.IndexOutOfBoundsException: Index: 6, Size: 0
> > > >
> > > > Submitting with 200 results errors with :
> > > > java.lang.IndexOutOfBoundsException: Index: 155, Size: 0
> > > >
> > > > The number seems to be random (I am guessing it is how far into the
> > > > form it gets before the error is encountered)
> > > >
> > > > Any help on this would be much appreciated.
> > > > I am including all the information that I believe to be important
> but
> > > > would have no problem including more.
> > > >
> > > > In the jsp form there is:
> > > >
> > > > <html:form action="/skuSearch" method="post" >
> > > >         <center>
> > > >                 <table width="400" border="1" align="center"
> > > > cellpadding="0" cellspacing="0">
> > > >                         <tr>
> > > >                                 <td>
> > > >                                         <table border="0"
> > > cellspacing="1"
> > > > cellpadding="1" width="100%" >
> > > >                                            <tr align="center">
> > > >                                                       <td><html:text
> > > > property="searchString" size="30"
> > > > maxlength="30"/></td>
> > > >
> > > >
> > > <td><html:submit>Search</html:submit></td>
> > > >                                            </tr>
> > > >                                            <tr><td
> > > colspan="2"></td></tr>
> > > >                                         </table>
> > > >                                 </td>
> > > >                         </tr>
> > > >                 </table>
> > > >         </center>
> > > > </html:form>
> > > >
> > > >
> > > > <html:form action="/searchResults" method="post" >
> > > > <center><p><html:submit>Add To Order</html:submit></p></center>
> > > > <table align ="center" width="90%" border=1>
> > > >         <tr>
> > > >                 <td>    Product                 </td>
> > > >                 <td>    Product Desc            </td>
> > > >                 <td>    Quantity                </td>
> > > >         </tr>
> > > >
> > > > <logic:notEmpty name="SkuSearchForm" property="results">
> > > >         <logic:iterate name="SkuSearchForm" property="results"
> > > > id="results">
> > > >         <tr>
> > > >                 <td>    <bean:write name="results"
> property="product"
> > > > />                        </td>
> > > >                 <td>    <bean:write name="results"
> > > property="description"
> > > > />                    </td>
> > > >                 <td>    <html:text name="results"
> > property="numProducts"
> > > > indexed="true" />
> > >
> > >
> > > post the getter method for the numProducts. that might be causing the
> > > problem.
> > >
> > >      </td>
> > > >         </tr>
> > > >         </logic:iterate>
> > > > </logic:notEmpty>
> > > >
> > > > <logic:empty name="SkuSearchForm" property="results">
> > > >                 <tr><td colspan="3" align="center">NO
> > RESULTS</td></tr>
> > > > </logic:empty>
> > > > </table>
> > > > </html:form>
> > > >
> > > > In the action (this action is only for the search results):
> > > >         public ActionForward execute(ActionMapping mapping,
> ActionForm
> > > > form,
> > > > HttpServletRequest request, HttpServletResponse response) throws
> > > > Exception
> > > >         {
> > > >                 SkuSearchForm skuform = (SkuSearchForm) form;
> > > >                 HttpSession session = request.getSession();
> > > >                 User user = new User();
> > > >                 Order order = new Order();
> > > >                 ArrayList products = new ArrayList();
> > > >
> > > >                 ArrayList results = new ArrayList();
> > > >                 user = (User)session.getAttribute("User");
> > > >                 order = user.getOrder(user.getCurrOrder());
> > > >                 products = order.getProducts();
> > > >                 int number = 0;
> > > >                 int count = 0;
> > > >
> > > >                 Iterator iter = results.iterator();
> > > > //there is nothing happening in here as there is no results for some
> > > > reason.
> > > >                 while(iter.hasNext())
> > > >                 {
> > > >                         Product p = (Product) iter.next();
> > > >                         if(p.getNumProducts() != 0 )
> > > >                         {
> > > >                                 products.add(p);
> > > >                         }
> > > >
> > > >                         count++;
> > > >                 }
> > > >                         {
> > > >                                 count = 1;
> > > >                                 Product p = new Product("TestProd "
> +
> > > > count, "TestDesc"+count + "
> > > > " +count, 10, new BigDecimal("101.0"));
> > > >                                 products.add(p);
> > > >                                 results.add(p);
> > > >                                 count++;
> > > >                         }
> > > >
> > > >                 order.setProducts(products);
> > > >                 order.setOrderId("ID12");
> > > >                 user.changeOrder(order, "ID12");
> > > >                 skuform.setResults(results);
> > > >
> > > >                 return mapping.findForward("success");
> > > >         }
> > > >
> > > > In the form (The methods I thought were appropriate):
> > > >
> > > >         public void setResults(ArrayList results)
> > > >         {
> > > >            this.results=results;
> > > >         }
> > > >
> > > >         public ArrayList getResults()
> > > >         {
> > > >            return this.results;
> > > >         }
> > > >
> > > >         public Product getResult(int index)
> > > >         {
> > > >                 if(this.results == null)
> > > >                 {
> > > >                         this.results = new ArrayList();
> > > >                 }
> > > >                 while(index>= this.results.size())
> > > >                 {
> > > >                         this.results.add(new Product());
> > > >                 }
> > > >
> > > >                 return (Product)results.get(index);
> > > >         }
> > > >
> > > >
> > > >
> > > > Thanks so much in advance for your time on this matter.
> > > >
> > > > Adam
> > > >
> > > >
> > >
> > >
> > > --
> > > Puneet
> > >
> > >
> >
> >
>
>

Re: Textfield problem with pulling value out.

Posted by Chris Pratt <th...@gmail.com>.
I don't think I've ever seen that technique before, but you have to remember
that size() is 1 based and index (or get(index) ) is 0 based.  So when
someone calls getNumProducts(5), your while loop fills in indexes 0, 1, 2,
3, and 4 (because then index and this.results.size() are both 5), then you
proceed to ask for results.get(5), which doesn't exist.  You should be able
to change your while list to something like:

while(index >= this.results.size() + 1) {
  this.results.add(new Product());
}

  (*Chris*)

On 10/19/06, Adam K <ad...@gmail.com> wrote:
>
> Here are the 2 get methods that I have.
>
> thanks again for all the help.
>
>
>     public int getNumProducts() {
>         return numProducts;
>     }
>
>
>     public int getNumProducts(int index)
>     {
>         if(this.results== null)
>         {
>             this.results = new ArrayList();
>         }
>         while(index >= this.results.size())
>         {
>             this.results.add(new Product());
>         }
>
>         Product p = (Product) results.get(index);
>         return p.getNumProducts();
>     }
>
> On 10/19/06, Puneet Lakhina <pu...@gmail.com> wrote:
> >
> > On 10/19/06, Adam K <ad...@gmail.com> wrote:
> > >
> > > Hi all I have been working on this probelm for the past couple of
> days,
> > > and
> > > don't seem to be making any progress on it.  I am fairly certain it is
> a
> > > problem with my understanding of struts, and as such it makes it quite
> > > difficult for me to solve the problem myself.
> > > I am trying to use a textfield and pull values from it.  The following
> > > explains the scenario.  User clicks on a page, page loads with a form
> > that
> > > has a textfield.  User enters search criteria and submits form.  This
> > > works
> > > fine.  Page returns with the search form and textfield, as well as a
> > > second
> > > form that displays the results of the search.  This also works
> > fine.  The
> > > user then goes through the results filling in numbers for each result
> > > indicating how many of each they would like to order and then submit
> the
> > > form.  This is where the problem results.  I end up gettting an error
> > from
> > > the page anytime I submit the form where there is 1 or more results.
> > > Submitting with no results works fine and the page loads correctly.
> > > Submitting with 1 result errors out with
> > >
> > > java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
> > >
> > > Submitting with 10 results errors out with:
> > > java.lang.IndexOutOfBoundsException: Index: 2, Size: 0
> > >
> > > Submitting with 100 results errors with :
> > > java.lang.IndexOutOfBoundsException: Index: 6, Size: 0
> > >
> > > Submitting with 200 results errors with :
> > > java.lang.IndexOutOfBoundsException: Index: 155, Size: 0
> > >
> > > The number seems to be random (I am guessing it is how far into the
> > > form it gets before the error is encountered)
> > >
> > > Any help on this would be much appreciated.
> > > I am including all the information that I believe to be important but
> > > would have no problem including more.
> > >
> > > In the jsp form there is:
> > >
> > > <html:form action="/skuSearch" method="post" >
> > >         <center>
> > >                 <table width="400" border="1" align="center"
> > > cellpadding="0" cellspacing="0">
> > >                         <tr>
> > >                                 <td>
> > >                                         <table border="0"
> > cellspacing="1"
> > > cellpadding="1" width="100%" >
> > >                                            <tr align="center">
> > >                                                       <td><html:text
> > > property="searchString" size="30"
> > > maxlength="30"/></td>
> > >
> > >
> > <td><html:submit>Search</html:submit></td>
> > >                                            </tr>
> > >                                            <tr><td
> > colspan="2"></td></tr>
> > >                                         </table>
> > >                                 </td>
> > >                         </tr>
> > >                 </table>
> > >         </center>
> > > </html:form>
> > >
> > >
> > > <html:form action="/searchResults" method="post" >
> > > <center><p><html:submit>Add To Order</html:submit></p></center>
> > > <table align ="center" width="90%" border=1>
> > >         <tr>
> > >                 <td>    Product                 </td>
> > >                 <td>    Product Desc            </td>
> > >                 <td>    Quantity                </td>
> > >         </tr>
> > >
> > > <logic:notEmpty name="SkuSearchForm" property="results">
> > >         <logic:iterate name="SkuSearchForm" property="results"
> > > id="results">
> > >         <tr>
> > >                 <td>    <bean:write name="results" property="product"
> > > />                        </td>
> > >                 <td>    <bean:write name="results"
> > property="description"
> > > />                    </td>
> > >                 <td>    <html:text name="results"
> property="numProducts"
> > > indexed="true" />
> >
> >
> > post the getter method for the numProducts. that might be causing the
> > problem.
> >
> >      </td>
> > >         </tr>
> > >         </logic:iterate>
> > > </logic:notEmpty>
> > >
> > > <logic:empty name="SkuSearchForm" property="results">
> > >                 <tr><td colspan="3" align="center">NO
> RESULTS</td></tr>
> > > </logic:empty>
> > > </table>
> > > </html:form>
> > >
> > > In the action (this action is only for the search results):
> > >         public ActionForward execute(ActionMapping mapping, ActionForm
> > > form,
> > > HttpServletRequest request, HttpServletResponse response) throws
> > > Exception
> > >         {
> > >                 SkuSearchForm skuform = (SkuSearchForm) form;
> > >                 HttpSession session = request.getSession();
> > >                 User user = new User();
> > >                 Order order = new Order();
> > >                 ArrayList products = new ArrayList();
> > >
> > >                 ArrayList results = new ArrayList();
> > >                 user = (User)session.getAttribute("User");
> > >                 order = user.getOrder(user.getCurrOrder());
> > >                 products = order.getProducts();
> > >                 int number = 0;
> > >                 int count = 0;
> > >
> > >                 Iterator iter = results.iterator();
> > > //there is nothing happening in here as there is no results for some
> > > reason.
> > >                 while(iter.hasNext())
> > >                 {
> > >                         Product p = (Product) iter.next();
> > >                         if(p.getNumProducts() != 0 )
> > >                         {
> > >                                 products.add(p);
> > >                         }
> > >
> > >                         count++;
> > >                 }
> > >                         {
> > >                                 count = 1;
> > >                                 Product p = new Product("TestProd " +
> > > count, "TestDesc"+count + "
> > > " +count, 10, new BigDecimal("101.0"));
> > >                                 products.add(p);
> > >                                 results.add(p);
> > >                                 count++;
> > >                         }
> > >
> > >                 order.setProducts(products);
> > >                 order.setOrderId("ID12");
> > >                 user.changeOrder(order, "ID12");
> > >                 skuform.setResults(results);
> > >
> > >                 return mapping.findForward("success");
> > >         }
> > >
> > > In the form (The methods I thought were appropriate):
> > >
> > >         public void setResults(ArrayList results)
> > >         {
> > >            this.results=results;
> > >         }
> > >
> > >         public ArrayList getResults()
> > >         {
> > >            return this.results;
> > >         }
> > >
> > >         public Product getResult(int index)
> > >         {
> > >                 if(this.results == null)
> > >                 {
> > >                         this.results = new ArrayList();
> > >                 }
> > >                 while(index>= this.results.size())
> > >                 {
> > >                         this.results.add(new Product());
> > >                 }
> > >
> > >                 return (Product)results.get(index);
> > >         }
> > >
> > >
> > >
> > > Thanks so much in advance for your time on this matter.
> > >
> > > Adam
> > >
> > >
> >
> >
> > --
> > Puneet
> >
> >
>
>

Re: Textfield problem with pulling value out.

Posted by Adam K <ad...@gmail.com>.
Here are the 2 get methods that I have.

thanks again for all the help.


    public int getNumProducts() {
        return numProducts;
    }


    public int getNumProducts(int index)
    {
        if(this.results== null)
        {
            this.results = new ArrayList();
        }
        while(index >= this.results.size())
        {
            this.results.add(new Product());
        }

        Product p = (Product) results.get(index);
        return p.getNumProducts();
    }

On 10/19/06, Puneet Lakhina <pu...@gmail.com> wrote:
>
> On 10/19/06, Adam K <ad...@gmail.com> wrote:
> >
> > Hi all I have been working on this probelm for the past couple of days,
> > and
> > don't seem to be making any progress on it.  I am fairly certain it is a
> > problem with my understanding of struts, and as such it makes it quite
> > difficult for me to solve the problem myself.
> > I am trying to use a textfield and pull values from it.  The following
> > explains the scenario.  User clicks on a page, page loads with a form
> that
> > has a textfield.  User enters search criteria and submits form.  This
> > works
> > fine.  Page returns with the search form and textfield, as well as a
> > second
> > form that displays the results of the search.  This also works
> fine.  The
> > user then goes through the results filling in numbers for each result
> > indicating how many of each they would like to order and then submit the
> > form.  This is where the problem results.  I end up gettting an error
> from
> > the page anytime I submit the form where there is 1 or more results.
> > Submitting with no results works fine and the page loads correctly.
> > Submitting with 1 result errors out with
> >
> > java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
> >
> > Submitting with 10 results errors out with:
> > java.lang.IndexOutOfBoundsException: Index: 2, Size: 0
> >
> > Submitting with 100 results errors with :
> > java.lang.IndexOutOfBoundsException: Index: 6, Size: 0
> >
> > Submitting with 200 results errors with :
> > java.lang.IndexOutOfBoundsException: Index: 155, Size: 0
> >
> > The number seems to be random (I am guessing it is how far into the
> > form it gets before the error is encountered)
> >
> > Any help on this would be much appreciated.
> > I am including all the information that I believe to be important but
> > would have no problem including more.
> >
> > In the jsp form there is:
> >
> > <html:form action="/skuSearch" method="post" >
> >         <center>
> >                 <table width="400" border="1" align="center"
> > cellpadding="0" cellspacing="0">
> >                         <tr>
> >                                 <td>
> >                                         <table border="0"
> cellspacing="1"
> > cellpadding="1" width="100%" >
> >                                            <tr align="center">
> >                                                       <td><html:text
> > property="searchString" size="30"
> > maxlength="30"/></td>
> >
> >
> <td><html:submit>Search</html:submit></td>
> >                                            </tr>
> >                                            <tr><td
> colspan="2"></td></tr>
> >                                         </table>
> >                                 </td>
> >                         </tr>
> >                 </table>
> >         </center>
> > </html:form>
> >
> >
> > <html:form action="/searchResults" method="post" >
> > <center><p><html:submit>Add To Order</html:submit></p></center>
> > <table align ="center" width="90%" border=1>
> >         <tr>
> >                 <td>    Product                 </td>
> >                 <td>    Product Desc            </td>
> >                 <td>    Quantity                </td>
> >         </tr>
> >
> > <logic:notEmpty name="SkuSearchForm" property="results">
> >         <logic:iterate name="SkuSearchForm" property="results"
> > id="results">
> >         <tr>
> >                 <td>    <bean:write name="results" property="product"
> > />                        </td>
> >                 <td>    <bean:write name="results"
> property="description"
> > />                    </td>
> >                 <td>    <html:text name="results" property="numProducts"
> > indexed="true" />
>
>
> post the getter method for the numProducts. that might be causing the
> problem.
>
>      </td>
> >         </tr>
> >         </logic:iterate>
> > </logic:notEmpty>
> >
> > <logic:empty name="SkuSearchForm" property="results">
> >                 <tr><td colspan="3" align="center">NO RESULTS</td></tr>
> > </logic:empty>
> > </table>
> > </html:form>
> >
> > In the action (this action is only for the search results):
> >         public ActionForward execute(ActionMapping mapping, ActionForm
> > form,
> > HttpServletRequest request, HttpServletResponse response) throws
> > Exception
> >         {
> >                 SkuSearchForm skuform = (SkuSearchForm) form;
> >                 HttpSession session = request.getSession();
> >                 User user = new User();
> >                 Order order = new Order();
> >                 ArrayList products = new ArrayList();
> >
> >                 ArrayList results = new ArrayList();
> >                 user = (User)session.getAttribute("User");
> >                 order = user.getOrder(user.getCurrOrder());
> >                 products = order.getProducts();
> >                 int number = 0;
> >                 int count = 0;
> >
> >                 Iterator iter = results.iterator();
> > //there is nothing happening in here as there is no results for some
> > reason.
> >                 while(iter.hasNext())
> >                 {
> >                         Product p = (Product) iter.next();
> >                         if(p.getNumProducts() != 0 )
> >                         {
> >                                 products.add(p);
> >                         }
> >
> >                         count++;
> >                 }
> >                         {
> >                                 count = 1;
> >                                 Product p = new Product("TestProd " +
> > count, "TestDesc"+count + "
> > " +count, 10, new BigDecimal("101.0"));
> >                                 products.add(p);
> >                                 results.add(p);
> >                                 count++;
> >                         }
> >
> >                 order.setProducts(products);
> >                 order.setOrderId("ID12");
> >                 user.changeOrder(order, "ID12");
> >                 skuform.setResults(results);
> >
> >                 return mapping.findForward("success");
> >         }
> >
> > In the form (The methods I thought were appropriate):
> >
> >         public void setResults(ArrayList results)
> >         {
> >            this.results=results;
> >         }
> >
> >         public ArrayList getResults()
> >         {
> >            return this.results;
> >         }
> >
> >         public Product getResult(int index)
> >         {
> >                 if(this.results == null)
> >                 {
> >                         this.results = new ArrayList();
> >                 }
> >                 while(index>= this.results.size())
> >                 {
> >                         this.results.add(new Product());
> >                 }
> >
> >                 return (Product)results.get(index);
> >         }
> >
> >
> >
> > Thanks so much in advance for your time on this matter.
> >
> > Adam
> >
> >
>
>
> --
> Puneet
>
>

Re: Textfield problem with pulling value out.

Posted by Puneet Lakhina <pu...@gmail.com>.
On 10/19/06, Adam K <ad...@gmail.com> wrote:
>
> Hi all I have been working on this probelm for the past couple of days,
> and
> don't seem to be making any progress on it.  I am fairly certain it is a
> problem with my understanding of struts, and as such it makes it quite
> difficult for me to solve the problem myself.
> I am trying to use a textfield and pull values from it.  The following
> explains the scenario.  User clicks on a page, page loads with a form that
> has a textfield.  User enters search criteria and submits form.  This
> works
> fine.  Page returns with the search form and textfield, as well as a
> second
> form that displays the results of the search.  This also works fine.  The
> user then goes through the results filling in numbers for each result
> indicating how many of each they would like to order and then submit the
> form.  This is where the problem results.  I end up gettting an error from
> the page anytime I submit the form where there is 1 or more results.
> Submitting with no results works fine and the page loads correctly.
> Submitting with 1 result errors out with
>
> java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
>
> Submitting with 10 results errors out with:
> java.lang.IndexOutOfBoundsException: Index: 2, Size: 0
>
> Submitting with 100 results errors with :
> java.lang.IndexOutOfBoundsException: Index: 6, Size: 0
>
> Submitting with 200 results errors with :
> java.lang.IndexOutOfBoundsException: Index: 155, Size: 0
>
> The number seems to be random (I am guessing it is how far into the
> form it gets before the error is encountered)
>
> Any help on this would be much appreciated.
> I am including all the information that I believe to be important but
> would have no problem including more.
>
> In the jsp form there is:
>
> <html:form action="/skuSearch" method="post" >
>         <center>
>                 <table width="400" border="1" align="center"
> cellpadding="0" cellspacing="0">
>                         <tr>
>                                 <td>
>                                         <table border="0" cellspacing="1"
> cellpadding="1" width="100%" >
>                                            <tr align="center">
>                                                       <td><html:text
> property="searchString" size="30"
> maxlength="30"/></td>
>
>                                                       <td><html:submit>Search</html:submit></td>
>                                            </tr>
>                                            <tr><td colspan="2"></td></tr>
>                                         </table>
>                                 </td>
>                         </tr>
>                 </table>
>         </center>
> </html:form>
>
>
> <html:form action="/searchResults" method="post" >
> <center><p><html:submit>Add To Order</html:submit></p></center>
> <table align ="center" width="90%" border=1>
>         <tr>
>                 <td>    Product                 </td>
>                 <td>    Product Desc            </td>
>                 <td>    Quantity                </td>
>         </tr>
>
> <logic:notEmpty name="SkuSearchForm" property="results">
>         <logic:iterate name="SkuSearchForm" property="results"
> id="results">
>         <tr>
>                 <td>    <bean:write name="results" property="product"
> />                        </td>
>                 <td>    <bean:write name="results" property="description"
> />                    </td>
>                 <td>    <html:text name="results" property="numProducts"
> indexed="true" />


post the getter method for the numProducts. that might be causing the
problem.

     </td>
>         </tr>
>         </logic:iterate>
> </logic:notEmpty>
>
> <logic:empty name="SkuSearchForm" property="results">
>                 <tr><td colspan="3" align="center">NO RESULTS</td></tr>
> </logic:empty>
> </table>
> </html:form>
>
> In the action (this action is only for the search results):
>         public ActionForward execute(ActionMapping mapping, ActionForm
> form,
> HttpServletRequest request, HttpServletResponse response) throws
> Exception
>         {
>                 SkuSearchForm skuform = (SkuSearchForm) form;
>                 HttpSession session = request.getSession();
>                 User user = new User();
>                 Order order = new Order();
>                 ArrayList products = new ArrayList();
>
>                 ArrayList results = new ArrayList();
>                 user = (User)session.getAttribute("User");
>                 order = user.getOrder(user.getCurrOrder());
>                 products = order.getProducts();
>                 int number = 0;
>                 int count = 0;
>
>                 Iterator iter = results.iterator();
> //there is nothing happening in here as there is no results for some
> reason.
>                 while(iter.hasNext())
>                 {
>                         Product p = (Product) iter.next();
>                         if(p.getNumProducts() != 0 )
>                         {
>                                 products.add(p);
>                         }
>
>                         count++;
>                 }
>                         {
>                                 count = 1;
>                                 Product p = new Product("TestProd " +
> count, "TestDesc"+count + "
> " +count, 10, new BigDecimal("101.0"));
>                                 products.add(p);
>                                 results.add(p);
>                                 count++;
>                         }
>
>                 order.setProducts(products);
>                 order.setOrderId("ID12");
>                 user.changeOrder(order, "ID12");
>                 skuform.setResults(results);
>
>                 return mapping.findForward("success");
>         }
>
> In the form (The methods I thought were appropriate):
>
>         public void setResults(ArrayList results)
>         {
>            this.results=results;
>         }
>
>         public ArrayList getResults()
>         {
>            return this.results;
>         }
>
>         public Product getResult(int index)
>         {
>                 if(this.results == null)
>                 {
>                         this.results = new ArrayList();
>                 }
>                 while(index>= this.results.size())
>                 {
>                         this.results.add(new Product());
>                 }
>
>                 return (Product)results.get(index);
>         }
>
>
>
> Thanks so much in advance for your time on this matter.
>
> Adam
>
>


-- 
Puneet