aspose file tools*
The moose likes Struts and the fly likes Treemap with logic iterator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Treemap with logic iterator" Watch "Treemap with logic iterator" New topic
Author

Treemap with logic iterator

Jayasri Alaparthi
Ranch Hand

Joined: Aug 14, 2006
Posts: 67
Hello friends,

In my project, I am getting the data from database and keeping it in the proporties with name values pair and setting that in pricingWorksheetForm.setProductTree((TreeMap)getServlet().getServletContext().getAttribute("productTree"));

and iterating in jsp

<logic:iterate id="prodTree" name="pricingWorksheetForm" property="treeSet" type="java.util.Map.Entry">
<bean efine id="product" name="prodTree" property="value" type="java.util.Properties"/><TR id="<%=prodTree.getKey()%>">

Please some one explain the code defined in jsp.


with regards,
Bhargavi.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
What are you asking? Does the code work? Does your form have a method named getTreeSet? I suspect that method returns "produceTree.values()".

- Brent
Anubhav Anand
Ranch Hand

Joined: May 18, 2007
Posts: 341

The <logic:iterate /> tag is used to iterate over a named collection�which contains a Collection, Enumerator,Iterator, Map, or Array�and evaluates its body for each Object in the collection.
The id attribut specifies a JSP scripting variable, exposed by the <logic: iterate /> tag, that will hold the current object in the named collection.This attribute is mandatory.
The name attribute specifies a scripting variable that represents the
collection to be iterated over. This attribute is optional.
The property attribute specifies the data member of the scripting variable,
identified by the name attribute, that contains a reference to a collection. This is also optional.
The type attribute provides the fully qualified class name of the element
being exposed from the collection. This object is referenced by the id attribute. This is also optional.

The <bean:define /> tag is used to retrieve the value of a named bean property and define it as a scripting variable, which will be stored in the scope specified by the toScope attribute.
The id attribute of <bean:define> specifies the scripting variable that will be created and stored in a scoped attribute that will be made
available with the value of the indicated property. This is mandatory attribute.
The name attribute specifies the attribute name of the bean whose
property is retrieved to define a new scoped attribute. This attribute is optional.
The property attribute identifies the property of the bean, specified by the name attribute, that is being retrieved. This is also optional.
Lastly, the type attribute provides the fully qualified class name of the value to be exposed as the id attribute.

Assuming that you have appropriate getters&setters in your formmbean.

Coming to your code snippet
pricingWorksheetForm.setProductTree((TreeMap)getServlet().getServletContext().getAttribute("productTree"));

<logic:iterate id="prodTree" name="pricingWorksheetForm" property="treeSet" type="java.util.Map.Entry">
<bean efine id="product" name="prodTree" property="value" type="java.util.Properties"/> <TR id="<%=prodTree.getKey()%>">


Here we have a we have a collection(TreeMap) called "productTree" ( probably set in session as it seems to be a formbean variable)

The logic iterate tag defines a jsp scripting variable as "prodTree" and this will contain the current object of the collection "productTree".
Now the bean define tag takes the object and gets the "product" variable and finally we have a scripplet that displays some property of productTree.
 
 
subject: Treemap with logic iterator
 
Similar Threads
Array dispaly
problem with logic:iterator in dividing the rows to two coloums
Qury problem?
Spring security multiple login pages
formatting problem