Announcement Announcement Module
Collapse
No announcement yet.
Model data is not coming to drop down list. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Model data is not coming to drop down list.

    Hi
    I am trying to display some data in to dropdown list when form is loaded.
    But i am unable to display it.
    I am getting data in to the list from db.Here is my log file.
    Code:
    2005-12-31 13:53:49,484 INFO [com.db.home.ProjectManagerJdbc] - List size->>>3
    2005-12-31 13:53:54,187 INFO [com.home.ProjectEntryController] - ClusterManagerMr. A
    2005-12-31 13:53:54,187 INFO [com.home.ProjectEntryController] - ClusterManagerMr. Y
    2005-12-31 13:53:54,187 INFO [com.home.ProjectEntryController] - ClusterManagerMr. B
    2005-12-31 13:53:54,187 INFO [com.home.ProjectEntryController] - ClusterManagerXXX
    2005-12-31 13:53:54,187 INFO [com.home.ProjectEntryController] - ClusterManagerhhhhh
    2005-12-31 13:53:54,187 INFO [com.home.ProjectEntryController] - ClusterManagerklkl


    Here is my controllerclass
    Code:
    public class ProjectEntryController extends SimpleFormController {
    	protected final Log logger = LogFactory.getLog(getClass());
    	private ProjectEntryJdbc jdbc;
    	
    	private ClusterManagerJdbc clusterManagerJdbc;
    	private ProjectManagerJdbc projectManagerJdbc;
    	
    	public void setProjectManagerJdbc(ProjectManagerJdbc jdbc) {
    		this.projectManagerJdbc = jdbc;
    	}
    
    	public void setClusterManagerJdbc(ClusterManagerJdbc jdbc) {
    		this.clusterManagerJdbc = jdbc;
    	}
    	public void setProjectEntryJdbc(ProjectEntryJdbc jdbc) {
    		this.jdbc = jdbc;
    	}
    
    	
    public ModelAndView onSubmit(Object command) throws ServletException {
    		
    		ProjectEntry projectEntry=new ProjectEntry();
    		
    		String projectName=((ProjectEntry)command).getProjectName();
    		String projectManager=((ProjectEntry)command).getProjectManager();
    		String clusterManager=((ProjectEntry)command).getClusterManager();
    	
    		int status = 0;
    		try {
    			status = jdbc.insertProject(projectName,projectManager,clusterManager);
    		} catch (Throwable  e) {
    			logger.error("Error in leaveEntry  *******", e);
    			e.printStackTrace();
    		}
    		logger.info("Success fully Inserted");
    		if (status == 1)
    			return new ModelAndView("ProjectEntry");
    		else
    			return new ModelAndView("home");
    	}
    	
    protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors)	throws Exception {
    
    	logger.info("*******************showForm");
    TeamMember teamMember = new TeamMember();
    List managerList = new ArrayList();
    List clusterManagerlist = new ArrayList();
    try {
    	managerList = projectManagerJdbc.getProjectManager();
    	
    } catch (Throwable e) {
    	e.getStackTrace();
    }
    try {
    	clusterManagerlist = clusterManagerJdbc.getClusterManagerList();
    } catch (Throwable e) {
    	logger.error("", e);
    	logger.info(e);
    	e.getStackTrace();
    }
    Iterator itr1 = clusterManagerlist.iterator();
    while (itr1.hasNext()) {
    	teamMember = (TeamMember) itr1.next();
    	logger.info("ClusterManager"+teamMember.clustureManagerName);
    }
    
    Map map = new HashMap();
    map.put("managerList", managerList);
    map.put("clusterManagerList", clusterManagerlist);
    
    return new ModelAndView("ProjectEntry", "Model", map);
    }	
    	
    protected ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception{
    	logger.info("**********INSIDE PROCESS FROM SUBMISSION********************");
    	if (!isFormSubmission(request))
    {
        return showForm(request, response, errors);
    }
    else
    {
        return onSubmit(request, response, command, errors);
    }
    }
    Here is my jsp file

    Code:
    <spring:bind path="ProjectEntry.projectManager">
    				<TD align="left">
    					<select name="projectManager">
    					<option value ="0">Select a project manager</option>
    					<c:forEach var="projectEntry" items="${Model.managerList}">
    					
    						<option value ="<c:out value="${projectEntry.projectManagerId}"/>"><c:out value="${projectEntry.projectManagerName}"/></option>
    					</c:forEach>  
    	</select>
    	</TD>
    	</spring:bind>
    			</TR>
    			<TR align=center bgcolor="#F2F5FF">
    				<TD align="left">
    					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Cluster Manager</b>
    	<spring:bind path="ProjectEntry.clusterManager">
    		<TD align="left">
    	<select name="clusterManager">
    <c:forEach var="teamMember" items="${Model.clusterManagerList}">
    <option value ="<c:out value="${teamMember.clustureManagerId}"/>"><c:out value="${teamMember.clustureManagerName}"/></option>
    					</c:forEach> 
    			</select>
    		</TD>
    </spring:bind>

  • #2
    if you want to send extra model data to the form, override the:
    protected Map referenceData(HttpServletRequest request) throws Exception
    method of the controller

    Comment


    • #3
      Hi shan,
      I am using showform method. As you said i also tried using reference data method. But i am getting the data. I am not able to display it . I think the problem is in JSP while displaying Model.
      Please have a look at code.

      Comment


      • #4
        Where you are doing this:
        Code:
        return new ModelAndView("ProjectEntry", "Model", map);
        Try this:
        Code:
        return new ModelAndView("ProjectEntry", map);

        In your JSP, where you are doing this:
        <c:forEach var="projectEntry" items="${Model.managerList}">

        Try this:
        Code:
        <c:forEach var="projectEntry" items="${managerList}">
        If that doesn't work, try inspecting the request.getAttributes() keySet using a debugger or just output it in the jsp. That will tell you for sure if the dropdowns are present.

        Other suggestions:
        The code that loads dropdown lists should be placed in the referenceData method.
        I'm not sure why you are needing to override the processFormSubmission method...it should work fine without overriding.

        Comment


        • #5
          Hi jeffry,
          Thank you very much. Now i got it working fine.

          Comment

          Working...
          X