This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Struts and the fly likes Access DAO Attributes? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Access DAO Attributes?" Watch "Access DAO Attributes?" New topic
Author

Access DAO Attributes?

J Ellis
Greenhorn

Joined: Aug 23, 2009
Posts: 27
Hey all,

I am trying to set up a Struts 2 project that has tables with dynamic columns (i.e., the user may add and remove fields from the table). As it is I load all of the fields and their values into the class' Attributes, but I am having a hard time figuring out if there is a Struts tag with which I can access the Attributes object from my JSP page. I believe I might be able to accomplish the same thing by loading the values into an Iterator and using the Struts iterator tag, but I was hoping to deal directly with the Attributes object.

Anyone have any ideas?


-TennSeven
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8935
    
    9

I don't have a good idea of your class structure here. Is Attributes a single object that stores all the database information, or is there a class structure that contains many instances of Attributres?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
J Ellis
Greenhorn

Joined: Aug 23, 2009
Posts: 27
Attributes is a single object that stores all of the key/value pairs for a single instance from the table. For instance, if the table was "Employees" one Employee instance (taken from the iteration of all instances in the table) would have one Attributes object whose toString() output would like like this:



If these were discrete variables in the instance class I could access them like this:
But I want the user to be able to add, say, a "phoneNumber" column to the "Employees" table, and so I cannot rely on variables to hold the values but instead need something flexible, like the Attributes object.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8935
    
    9

Are you using java.util.jar.Attributes? The iterator tag says it works with java.util.Map. Attributes implements Map. It should just work. See an example here.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Access DAO Attributes?