In order to create a dropdown list in struts2 <s:select /> is used on a jsp page. Just define a action name for displaying a dropdown list having value from database. In action class we define a list, and its getter and setter. and in execute method we add the elements in the list from the database. On returning success page we get all the list elements by OGNL on jsp page as follows: <s:select name="mydrop_down" list="%{sports}" /> where list is a Iterable source to populate from. If the list is a Map (key, value), the Map key will become ´value´ parameter of option tag and the Map value will become the option tag body. Whatever you want to create a List/Map/Array in your action class and provide its getter and setter. How the list will be picked form the ActionClass in jsp that will be handled by the framewrok itself. Action Class MyAction.java: -------------------------------------- public class MyAction extends ActionSuport{ private List<String> sports; //can be array or map etc //generate getters and setters for sports public String execute() throws Exception{ sports = init the List and fill it // can fill the list from database return SUCCESS; } } I hope you will understand. | 0 |
By: [email protected] On: Sun Jul 24 14:39:41 IST 2016 0 0 0 | 0 |
Are You Satisfied :0Yes0No |