The moose likes Struts and the fly likes struts tags Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts tags" Watch "struts tags" New topic

struts tags

siraj baig
Ranch Hand

Joined: Jul 11, 2006
Posts: 42
I have a javabean and a hash map created in a jsp file.
i am creating 2 obj's for the bean and want to store in the hash map
and display.

And how to display with tags ( bean:write) (with out using scriptlet)

Thangs in advance
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
First of all, it's important to understand that Struts is an MVC framework, which means that it expects you will develop your application according to the principles of MVC. One of those principles is that you keep view logic separate from business logic and don't mix the two.

By putting logic to populate data structures in a JSP, you violate this principle. Consequently, you will not get a lot of help from Struts (or from the JSP or JSTL specs either for that matter) when you do violate this principle. The correct place to populate data structures in a Struts application is in an Action class, or better yet, in a business layer class called by an Action class.

Regarding ways to store values in a HashMap without using scriptlets: It's important to remember that both the JSP spec and the JSTL spec were written with the assumption that you would be using JavaBeans to convey information to a JSP, so it's quite easy to manipulate objects that follow the JavaBean specification. A HashMap, however, is not a JavaBean. It does not follow the JavaBean convention of of getXXX and setXXX for its methods. Consequently, there is no elegant way to set values in HashMaps either with JSP tags or Struts tags.

However, since Hashmaps are used quite a bit, there are ways to retrieve values from HashMaps. If you have a HashMap with Strings as both key and value, you can reference it like this:
Which will be interpreted as:
You can also iterate through a HashMap using the <logic:iterate> tag. Each element retrieved will be of type Map.Entry, which has a key and a value property.

Consultant, Sima Solutions
I agree. Here's the link:
subject: struts tags
jQuery in Action, 3rd edition