File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use hashmap in logic:iterate

 
Janelle Bullus
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
R. Shellbay
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Janelle Bullus
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Janelle Bullus
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Janelle Bullus
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Anselm Paulinus
Ranch Hand
Posts: 390
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic