Hello there.
I have a form...which is actually an array of forms:
public class LineItemDisplayForm extends BaseForm
{
protected String count;
protected int lineItemCount;
protected LineItemForm[] lineItemForms;
/**
* @return Returns the lineItemCount.
*/
public int getLineItemCount()
{
return lineItemCount;
}
/**
* @param lineItemCount The lineItemCount to set.
*/
public void setLineItemCount(int theCount)
{
lineItemCount = theCount;
//make new array of lineitemforms with size of passed in count
LineItemForm[] tempLineItemForms = new LineItemForm[theCount];
//loop over existing lineitemforms array and copy into new lineitemforms array
for (int i = 0; i < theCount; i++)
{
tempLineItemForms = lineItemForms;
}
//set existing array to null
lineItemForms = null;
//set existing array equal to new array
lineItemForms = tempLineItemForms;
}
/**
* @return Returns the lineItemForms.
*/
public LineItemForm[] getLineItemForms()
{
if (lineItemForms == null)
{
lineItemForms = new LineItemForm[lineItemCount];
for (int i = 0; i < lineItemCount; i++)
{
lineItemForms = new LineItemForm();
}
}
return lineItemForms;
}
/**
* @param lineItemForms The lineItemForms to set.
*/
public void setLineItemForms(LineItemForm[] forms)
{
if (forms == null)
{
lineItemForms = new LineItemForm[lineItemCount];
}
lineItemForms = forms;
if (forms != null)
{
lineItemCount = lineItemForms.length;
}
}
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
{
ActionErrors errors = new ActionErrors();
boolean lineItemsEntered = false;
//line items
if (lineItemForms != null)
{
for (int i = 0; i < lineItemForms.length; i++)
{
lineItemsEntered = lineItemForms.validate(errors, "lineItemForms", Integer.toString(i + 1)) || lineItemsEntered;
}
}
return (errors);
}
}
/**
* @return Returns the count.
*/
public String getCount()
{
return count;
}
/**
* @param count The count to set.
*/
public void setCount(String theCount)
{
count = theCount;
}
When I submit this form I want to validate the submitted data. However, whenever I call the validate() method above lineItemForms is always coming back null. I realize that I need to instantiate the correct number of forms...for example, if there are 30 items in the array...i realize that i need to initialize each of those 30 items. I have a hidden field holding that value which is called "count" as you can see above.
However, no matter what I do, I can't get struts to populate the array of forms which i submitted. Help?
Shouldn't this be coming back populated with the data that I've submitted? How can I make this happen so I can validate the data?
Thank you so much.
bryan
I have a form...which is actually an array of forms:
public class LineItemDisplayForm extends BaseForm
{
protected String count;
protected int lineItemCount;
protected LineItemForm[] lineItemForms;
/**
* @return Returns the lineItemCount.
*/
public int getLineItemCount()
{
return lineItemCount;
}
/**
* @param lineItemCount The lineItemCount to set.
*/
public void setLineItemCount(int theCount)
{
lineItemCount = theCount;
//make new array of lineitemforms with size of passed in count
LineItemForm[] tempLineItemForms = new LineItemForm[theCount];
//loop over existing lineitemforms array and copy into new lineitemforms array
for (int i = 0; i < theCount; i++)
{
tempLineItemForms = lineItemForms;
}
//set existing array to null
lineItemForms = null;
//set existing array equal to new array
lineItemForms = tempLineItemForms;
}
/**
* @return Returns the lineItemForms.
*/
public LineItemForm[] getLineItemForms()
{
if (lineItemForms == null)
{
lineItemForms = new LineItemForm[lineItemCount];
for (int i = 0; i < lineItemCount; i++)
{
lineItemForms = new LineItemForm();
}
}
return lineItemForms;
}
/**
* @param lineItemForms The lineItemForms to set.
*/
public void setLineItemForms(LineItemForm[] forms)
{
if (forms == null)
{
lineItemForms = new LineItemForm[lineItemCount];
}
lineItemForms = forms;
if (forms != null)
{
lineItemCount = lineItemForms.length;
}
}
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
{
ActionErrors errors = new ActionErrors();
boolean lineItemsEntered = false;
//line items
if (lineItemForms != null)
{
for (int i = 0; i < lineItemForms.length; i++)
{
lineItemsEntered = lineItemForms.validate(errors, "lineItemForms", Integer.toString(i + 1)) || lineItemsEntered;
}
}
return (errors);
}
}
/**
* @return Returns the count.
*/
public String getCount()
{
return count;
}
/**
* @param count The count to set.
*/
public void setCount(String theCount)
{
count = theCount;
}
When I submit this form I want to validate the submitted data. However, whenever I call the validate() method above lineItemForms is always coming back null. I realize that I need to instantiate the correct number of forms...for example, if there are 30 items in the array...i realize that i need to initialize each of those 30 items. I have a hidden field holding that value which is called "count" as you can see above.
However, no matter what I do, I can't get struts to populate the array of forms which i submitted. Help?
Shouldn't this be coming back populated with the data that I've submitted? How can I make this happen so I can validate the data?
Thank you so much.
bryan