| Author |
logic:iterate tag problem
|
jothish chokkalingam
Ranch Hand
Joined: Jan 02, 2006
Posts: 50
|
|
Hi guys, I m using logic:iterate tag to display a queried data(rows) from database but i m getting the last row in the display... i couldn't find my mistake. i m using hashmap to store the rows from database and passing the hashmap with request variable to jsp to display. my logic:iterate tag goes like this <logic:iterate name="details" id="i" scope="request"> <tr> <td><bean:write name="login" property="name"/></td> <td><bean:write name="login" property="mail"/></td> <td><bean:write name="login" property="loc"/></td> </tr> </logic:iterate> id "i" is the iterator key i m using in action class "details" is the string i m setting in request.setAttribute() method in action class. and my action class is [B][/B] where login form is the form bean which has the variables name,mail and loc And one more thing I m using key as Integer in put() method whethr my syntax is correct??? help urgently needed [ February 03, 2006: Message edited by: jothish chokkalingam ]
|
jothish
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
The code in your Action is just resetting the properties of the same object over and over again and then putting references to the same object in each member of the HashTable. I don't think that's what you intended. You need to change the code to instantiate a new bean for reach row of the database read. Another thing: Your ActionForm is intended to have a one to one relatoinship with the JSP. There shouldn't be more than one of them. So, this HashMap you're creating should have instances of a regular javaBean, not instances of the ActionForm bean you defined in struts-config.xml Here's an example of the code: Here's how your JSP code should look: <logic:iterate name="details" id="i" scope="request"> <bean:define id="loginInfo" name="i" property="value" /> <tr> <td><bean:write name="loginInfo" property="name"/></td> <td><bean:write name="loginInfo" property="mail"/></td> <td><bean:write name="loginInfo" property="loc"/></td> </tr> </logic:iterate> When you iterate over a Hashmap, the iterator produces an object of type Map.Entry. This object has a key and a value property. Your Login object is stored in the value property.
|
Merrill
Consultant, Sima Solutions
|
 |
jothish chokkalingam
Ranch Hand
Joined: Jan 02, 2006
Posts: 50
|
|
Thanks Merrill It is working fine but it is not displaying in correct order as it is stored in Oracle db
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
|
A HashMap is not guaranteed to display the results in any particular order when you iterate through it. Any of the implementations of the java.util.List interface will redisplay the items in the order they were placed in the list, as will a TreeMap.
|
 |
jothish chokkalingam
Ranch Hand
Joined: Jan 02, 2006
Posts: 50
|
|
ok merill i can do that using list thanks man
|
 |
 |
|
|
subject: logic:iterate tag problem
|
|
|