• 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 ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Map and Iterator from a database in Struts 2.0  RSS feed

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:



 
Ranch Hand
Posts: 93
Java Python Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As the link suggests, using only the ArrayList would suffice.
 
Preet Dhillon
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
Java Python Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!