Announcement Announcement Module
Collapse
No announcement yet.
Problem facing in poulating dropdown, by getting values from the database Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem facing in poulating dropdown, by getting values from the database

    Hi all,

    I have got one entry page, where i want to populate the dropdowns by getting the values from the database and clicking on the submit button, the selected values will be submitted to the database.

    For submitting I have onSubmit() method in the controller and for default i have formBackingObject() method.

    In the formBackingObject() method, I am able to get the values (that I want to populate into the dropdowns) from the database in the form of List.

    Now my problem is how can I able to return the List and how can I be able to iterate the List in dropdown in the JSP page .

    My controller class is as follows:

    Code:
    public class MemberEntryController extends SimpleFormController {
    
    	/** Logger for this class and subclasses */
    	protected final Log logger = LogFactory.getLog(getClass());
        private InsertMemberJdbc memberJdbc;
    	ProjectManagerJdbc jdbc;
    	/**Sn*/
    	public void setInsertMemberJdbc(InsertMemberJdbc jdbc)
    	{
    		this.memberJdbc=jdbc;
    	}
    	
    	public void setProjectManagerJdbc(ProjectManagerJdbc jdbc) {
    		this.jdbc = jdbc;
    	}
    
    	public ModelAndView onSubmit(Object command) throws ServletException {
    		TeamMember teamMember = new TeamMember();
    		int empNo=((TeamMember)command).getEmpNo();
    		String empName=((TeamMember)command).getEmpName();
    		String projectName = ((TeamMember)command).getProjectName();
    		int projectManagerId = ((TeamMember)command).getProjectManagerId();
    		int clusterManagerId = ((TeamMember)command).getClustureManagerId();
    		String designation = ((TeamMember)command).getDesignation();
    		String location = ((TeamMember)command).getLocation();
    		String psaGrade = ((TeamMember)command).getPsaGrade();
    
    		int status = 0;
    		try{
    		status = memberJdbc.insert(empNo,empName,designation, projectManagerId,clusterManagerId,location,psaGrade,projectName);
    		} catch (Exception e) {
    			logger.error(e.getStackTrace());
    		}
    		Map map = new HashMap();
    		if(status==1){
    			return new ModelAndView("NewMemberEntry","Model",map);
    		} else{
    			return new ModelAndView("NewMemberEntry","Model",map);
    		}
    	}
    
    	protected Object formBackingObject(HttpServletRequest request)
    			throws ServletException {
    		TeamMember teamMember = new TeamMember();
    		List list = new ArrayList();
    		try {
    			list = jdbc.getProjectManager();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		Iterator itr = list.iterator();
    		while(itr.hasNext()){
    			teamMember = (TeamMember)itr.next();
    		
    		}
    		return teamMember;
    	}
    }

    Please help me.

    Thanks and Regards
    Sasikanth

  • #2
    See my reply to your other question. You need to put the information you want visible in the JSP as objects in your ModelAndView. In your code here, you're not doing anything with the map. I'd be tempted to change your code to something like this:

    Code:
    ModelAndView mv=new ModelAndView("NewMemberEntry");
    mv.addObject("somethingYouWantDisplayed",anObject);
    mv.addObject("somethingElseToDisplay",anotherObject);
    return mv;
    Get the idea?

    Comment

    Working...
    X