Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

struts tags

Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic