File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Dropdown creation dynamically from DB lookup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Dropdown creation dynamically from DB lookup" Watch "Dropdown creation dynamically from DB lookup" New topic
Author

Dropdown creation dynamically from DB lookup

Dushyant Chhetri
Ranch Hand

Joined: Oct 28, 2009
Posts: 75
Hi All,

I am trying to create a dropdown menu on using struts2 .
I am implementing the UI on jsp with struts taglib.

Now I want to populate the data on the dropdown froma database.
For this I have used the following and created an arraylist



The action for the above submit form is



However I am getting the following error




Please suggest me where I am going wrong.

Sunil Sunny
Ranch Hand

Joined: Oct 18, 2011
Posts: 41
boss you are uing MVC architecture why you are performing "database operations" on your view. i would suggest you to create an action first and you must create a list in its execute function. and
1. you must declare a "List Type Variable" hardware list.2. Fill the list as you have filled in your UI.
3. then create setter and getter for that List variable "hardwarelist".
4. after that you can set <s:select list="hardwarelist" headerKey="0" headerValue="Select Device" />
this will work



Remember list attribute of select will be same as the list variable name you declar in your action.


Do not forget to make entry in Struts.xml as:

<action name="Your cation in which you have mak your list" class="the action class">
<result name="success">YourJsp Page</result>

</action>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Dropdown creation dynamically from DB lookup
 
Similar Threads
Map not being resolved (FIXED)
Need to know if I am doing this right or not
Struts2 newB: some simple questions
Populating a list of Objects in Struts2
DropDown Menu error in Struts 2