i am using indexed properties in my
struts application , and all i well except that it doesnt do validation. My form bean is populated with a list of objects and upon submission i want errors listed for each object's invalid values.
Following is the
JSP:
/////////////////////////////////////////////////////////////////////
<html:form action="invoice.form?action=updatePO" method="post">
<logic:iterate id="purchaseOrderProduct" name="invoicePOForm" property="purchaseOrderProductList">
<html:hidden name="purchaseOrderProduct" property="productId" indexed="true"/>
<tr>
<td><bean:write name="purchaseOrderProduct" property="productId"/></td>
<td><bean:write name="purchaseOrderProduct" property="productTitle"/></td>
<td><bean:write name="purchaseOrderProduct" property="orderedQty"/></td>
<td><bean:write name="purchaseOrderProduct" property="receivedQty"/></td>
<td><bean:write name="purchaseOrderProduct" property="invoicedQty"/></td>
<td><bean:write name="purchaseOrderProduct" property="costPrice"/></td>
<c:if test="${purchaseOrderProduct.clearedStatus==0}">
<td>£<html:text name="purchaseOrderProduct" property="invoiceUnitPrice" size="30" indexed="true"/></td>
<td>£<html:text name="purchaseOrderProduct" property="invoiceTotalPrice" size="30" indexed="true"/></td>
<td><html:text name="purchaseOrderProduct" property="invoiceQty" size="30" indexed="true"/></td>
<td>Clear<html:multibox property="selectedProductIds"><bean:write name="purchaseOrderProduct" property="productId"></bean:write></html:multibox> </td>
</c:if>
<c:if test="${purchaseOrderProduct.clearedStatus==1}">
<td>£<bean:write name="purchaseOrderProduct" property="invoiceUnitPrice"/> </td>
<td>£<bean:write name="purchaseOrderProduct" property="invoiceTotalPrice"/> </td>
<td><bean:write name="purchaseOrderProduct" property="invoiceQty"/> </td>
<td>Cleared</td>
</c:if>
<td><html:errors property="invalidInvoicePrice"></html:errors></td>
</logic:iterate>
<%-- <td<html:errors property="invalidInvoicePrice"></html:errors></td>-- This bit fails as errors maybe of a number of objects' values.%>
</tr>
////////////////////////////////////////////////
any idea how to generate the errors messages.
Following is the error handling method in the form bean:
public ActionErrors validateForm(ActionMapping actionMapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if(getPurchaseOrderProductList().size() >0)
{
for(PurchaseOrderProduct pop:m_aPurchaseOrderProductList) {
if (pop.getInvoiceUnitPrice()<0)
{
StrutsUtils.addActionError(errors,INVALID_INVOICE_PRICE,ERROR_INVALID_INVOICE_PRICE);
}
}
}
return errors;
}
}