Forums Register Login

how to use hashmap in logic:iterate

+Pie Number of slices to send: Send
Now i want to display four list columns within a table.
example:
<logic:iterate name="rowSet" property="hashMap" id="rowSetObj">
<tr>
<td><bean:write name="rowSetObj" property="v1"></td>
<td><bean:write name="rowSetObj" property="v2"></td>
<td><bean:write name="rowSetObj" property="v3"></td>
<td><bean:write name="rowSetObj" property="v4"></td>
</tr>
</logic:iterate>
Can you help me?
how do i need to do with a javabean.
+Pie Number of slices to send: Send
Welcome to the Ranch hi_dwk!
You'll find this forum a great place to seek help on JSP pages, and there aren't many rules you'll have to worry about, but one is that proper names are required. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
Thanks!
bear
JSP Fourm Bartender
+Pie Number of slices to send: Send
First of all, The iterate tag iterates on a collection. You may either specify an object that itself is a collection, or you may set the property attribute in order to tell <logic:iterate> which method on the object that returns a collection.
Iterate will then loop through that collection, using the iterator() method that all Collections have.
A HashMap is not a collection, and hence I would have thought the jsp-compiler would fail when finding the wrong data type.
Also.... The element contained in the collection must be beans...
When using <bean:write ... property="foo"/> The object that is actually operated on, should have a method getFoo() .

Hope this was some help...
+Pie Number of slices to send: Send
http://jakarta.apache.org/struts/doc-1.0.2/struts-logic.html#iterate
In logic:iterate, it says that
The collection to be iterated over MUST conform to one of the following requirements in order for iteration to be successful:
An array of Java objects (but not primitive data types such as "int")
An implementation of java.util.Collection, including ArrayList and Vector.
An implementation of java.util.Enumeration.
An implementation of java.util.Iterator.
An implementation of java.util.Map, including HashMap, Hashtable, and TreeMap. NOTE - See below for additional information about accessing Maps.
however i dont know how to use it?
Can you help me?
+Pie Number of slices to send: Send
 

Originally posted by Bear Bibeault:
Welcome to the Ranch hi_dwk!
You'll find this forum a great place to seek help on JSP pages, and there aren't many rules you'll have to worry about, but one is that proper names are required. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
Thanks!
bear
JSP Fourm Bartender


Thanks for your advise.
however this name is easy for me.
Because i always forget my net name so I select this.
And name is just showing who use it. Do you think so?
Can you show me how to see my topics withing easy way?
+Pie Number of slices to send: Send
Please re-read the policy. The name you need to change is your display name, not your login name, which is the only one you need to remember.
Please be advised that failing to comply with the naming convention will result in your account being closed, and that would be a shame.
bear
+Pie Number of slices to send: Send
 

Originally posted by Bear Bibeault:
Please re-read the policy. The name you need to change is your display name, not your login name, which is the only one you need to remember.
Please be advised that failing to comply with the naming convention will result in your account being closed, and that would be a shame.
bear


Sorry, i do at once.
Can you show me how to see my topics withing easy way?
+Pie Number of slices to send: Send
Your code will not work as it is right now. The value stored in a hashtable are in key value pairs.
logic:iterate only iterates over those values stored in the map sequentially;
something like
<logic:iterate name="rowSet" property="hashMap" id="rowSetObj">
<tr>
<td><bean:write name="rowSetObj" property="value"></td>
</tr>
</logic:iterate>
does make sense; so that on every iteration it picks the next value on the hashtable starting from the first value untill it iterates the whole hashtable.
it seems to me you are trying to force it to print four values that should have been printed in four iterations.
On the alternative your code should work if you had a key pointing on to four different values and as much as I know this is not possible with hashtable or any of the classes that implement the map interface.
Let us know when you finally resolve this issue and how you resolved it.
+Pie Number of slices to send: Send
 

Sorry, i do at once.


Thanks for understanding. Problem is, the new name you chose is invalid as well. Please read the policy. Your display name must consist of a first and last name. Sorry to be such a pest, but the policy exists for good reason.
To answer another of your questions, you can find your recently posted topics by visiting your profile.
hth,
bear
Today you are you, that is turer than true. There is no one alive who is youer than you! - Seuss. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 4059 times.
Similar Threads
multibox query
how to do a pagination like "Page: 1 2 3 4 5 6 7" in a jsp ?
nested logic:iterate
Iterate Hashmap through struts
how to do a Pagination like "Page:1 2 3 4 5 6 " in a jsp?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 22:39:28.