0

I trying to populate the dropdown list when page was loaded.But it is not loaded in UserPage.jsp from Controller.on submit method and also wrote referencedata method.

Controller:-

public ModelAndView onSubmit(HttpServletRequest request,
            HttpServletResponse response, Object command, BindException errors)
            throws Exception {

        log.info("onSubmit handleRequest method"
                + request.getParameter("username"));
        System.out.println("onSubmit handleRequest method"
                + request.getParameter("username"));
        String username = "", password = "";
        username = request.getParameter("username");
        password = request.getParameter("password");

        UserBean ubean = null;

        System.out.println("After shownform method called");
        HttpSession session = request.getSession(true);
        try {
            ubean = userservice.chkUsername(username, password);
            System.out.println("Information" + ubean.getUsername());
        } catch (DataException ex) {
            ex.printStackTrace();

            // throw ex;
        }
        session.setAttribute("User", ubean);
        EmpPersonalBean personalBean = new EmpPersonalBean();
        return new ModelAndView("jsp/UserPage", "EmpPersonalBean", personalBean);
    }
                 protected Map referenceData(HttpServletRequest request) throws Exception {
        log.info("UserDBBoardController======================referenceData");
        Map referenceData = new HashMap();
        List deparementList = new ArrayList();
        deparementList = userservice.getDeparmentList();
        referenceData.put("deparmentList", deparementList);
        return referenceData;

    }

UserPage.jsp

<%@ page language="java" import="com.aims.bean.*,java.util.HashMap" contentType="text/html;charset=utf-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<html>
<head>
<title>AAI</title>
</head>
<body>
<form:form method="post" modelAttribute="EmpPersonalBean" action="userpage.htm">
<table>
<tr>
    <td>Welcome <%=((UserBean)session.getAttribute("User")).getUsername()%></td>
</tr>
        <tr>

        <td>Department</td>
        <td><form:select path="deparment">
                      <form:option value="NONE" label="--- Select ---" />
                      <form:options items="${deparmentList}" />
                       </form:select>
        </td>
    </tr>
</tr>
</table>
</form:form>
</body>
</html>


public class DepartmentBean {
private String deptcode,deptname;

public String getDeptcode() {
    return deptcode;
}

public void setDeptcode(String deptcode) {
    this.deptcode = deptcode;
}

public String getDeptname() {
    return deptname;
}

public void setDeptname(String deptname) {
    this.deptname = deptname;
}

}

And also attached displaying dropdown list in the userpage.sjpenter image description here

Please help me.How to resolve the issue.

4

2 回答 2

0
   <td>Department</td>
    <td><form:select path="deparment">
         <form:option value="NONE" label="--- Select ---" />
          <c:forEach var="department" items="${deparmentList}">
            <form:option value="${department}" label="${department}" />
          </c:forEach>
          </form:select>
    </td>





ModelAndView mav = new ModelAndView("viewName");


mav.addObject("deparmentList", deparementList);


return mav;

返回模型和视图对象。

于 2012-06-14T07:23:44.013 回答
0

您还需要在标签中指定itemLabelitemValue属性。<form:options/>

更新

在您的 jsp 页面中替换此行。我认为它应该可以解决您的问题。

<form:options items="${deparmentList}" itemLabel="deptname" itemValue="deptcode" />

希望这对您有所帮助。干杯。

于 2012-06-14T07:25:17.757 回答