If you make your Item class returns an Error object, you can avoid the errorCodeList, something like this:
public class Item { private int id=0; private MyError error;
/** * @return Returns the error. */ public MyError getError() { return error; }
/** * @param error The error to set. */ public void setError(MyError error) { this.error = error; }
/** * @return Returns the id. */ public int getId() { return id; }
/** * @param id The id to set. */ public void setId(int id) { this.id = id; }
/** * @param id */ public Item(int id) { super(); this.id = id; } }
assume that you have MyError class defined as a JavaBean with two properties errorCode (int) and errorString (String).
in your jsp: <%
java.util.Collection itemList = new java.util.ArrayList();
hqn.Item item1 = new hqn.Item(1); item1.setError( new hqn.MyError(1, "Error Description 1") );
itemList.add( item1 );
hqn.Item item2 = new hqn.Item(2); item2.setError( new hqn.MyError(2, "Error Description 2") );
request.setAttribute("itemList", itemList );
%>
Using JSTL forEach tag:
<c:forEach items="${itemList}" var="item"> Item ID= <c:out value="${item.id}"/><BR> Error Code: <c:out value="${item.error.errorCode}"/><BR> Error Desc: <c:out value="${item.error.errorString}"/><BR> </c:forEach>
Using logic:iterate tag:
<logic:iterate id="item" name="itemList"> Item Id= <bean:write name="item" property="id"/><BR> <bean:define id="error" name="item" property="error"/> Error Code: <bean:write name="error" property="errorCode"/><BR> Error Desc: <bean:write name="error" property="errorString"/><BR> </logic:iterate>
I'd recommend you to use JSTL.
--hqn
On Jan 5, 2004, at 4:39 PM, ngonqua wrote:
I'm very new to struts so please be kindly.
I have two Arraylist call itemList and errorCodeList. The itemList contains list of Item object. The item object has a property calls errorCode which returns an error code in int (1-50). I want to display the error description associates to that error code. How can I pass in the error code to the errorCodeList the get the error description.
Item Error Description -------- ------------------------- item1 description1 item2 description2 item3 description1 . . . .