aspose file tools*
The moose likes Struts and the fly likes Map and Iterator from a database in Struts 2.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Map and Iterator from a database in Struts 2.0" Watch "Map and Iterator from a database in Struts 2.0" New topic
Author

Map and Iterator from a database in Struts 2.0

Preet Dhillon
Greenhorn

Joined: May 20, 2008
Posts: 24
Hello,

I am in the process to convert this sample app from Apache site http://struts.apache.org/release/2.1.x/docs/crud-demo-i.html to use a database back end.

I am able to successfully populate a drop-down from the database but I am not sure if my code is correct. Here is the code original code:



Please take a look to see if it all makes sense - I need to have both list and Map return types. Here is my updated code to incoroporate database:



Karthik Jayachandran
Ranch Hand

Joined: Feb 18, 2009
Posts: 88

As the link suggests, using only the ArrayList would suffice.
Preet Dhillon
Greenhorn

Joined: May 20, 2008
Posts: 24
Thank you. If I understand you correctly I don't need the MAP...

I need to a step further with this and add department names in French as well. The drop-down needs to be populated in user’s locale choice.

What would be the best way to do that add another column to the table “name_fr” or add new row for each locale and have column named “locale” hold the values (en and fr)?

How and where would I access user’s locale and pass to the SQL query (i.e., jsp, action or DAO).

Thanks again!
Karthik Jayachandran
Ranch Hand

Joined: Feb 18, 2009
Posts: 88

Both of these strategy would work.

You can get Locale by calling in action or in jsp as

More discussed in here and here
Preet Dhillon
Greenhorn

Joined: May 20, 2008
Posts: 24

Perfect! Thank you. This is exactly what I was looking for...

Wondering if there is a way to improve the duplicated dropdown code? For example, is it possible to just update the listValue based on the locale rather than write the complete select twice.



Preet Dhillon
Greenhorn

Joined: May 20, 2008
Posts: 24
I am stumbled again on trying to implement a nested iterator using this sample.

http://struts.apache.org/release/2.1.x/docs/crud-demo-i.html

In the doList() method of the action, I need to add another iterator that should be populated by id of the exiting list (employee.employeeid)





I have already created a table in the database with this relationship. I have also got the service, model and dao to extract the data from the database by a given employeeid. But I am completely lost as to how and where to pass the employeeid parameter to populate the sub-list to generate the nested iterator.

Any ideas how to connect the nested list. This nested list is supposed to populate different form fields. For example, radio buttons, check boxes etc...

Preet Dhillon
Greenhorn

Joined: May 20, 2008
Posts: 24
Not sure if this is the best approach but it works so I am going to mark it as resolved...


Added the child list to the model:

and called the options within the while loop of the parent list:
 
Consider Paul's rocket mass heater.
 
subject: Map and Iterator from a database in Struts 2.0