在Spring MVC Controller中,使用表单提交时,Form值为null

时间:2014-03-28 17:07:17

标签: jquery spring spring-mvc model-view-controller controller

从另一个jsp的菜单选项中,它执行" ReportPage"在控制器中,组合框中填充了值,并在提交表单后,执行" processReport"在控制器中... 表单值打印为空,即combox值。如何获取控制器中的comboBox值?

另外只是为了让你知道我已经尝试过使用$ .POST(..,comboBoxValue),我在控制器中得到了值,但是后来在流程中我遇到了一些问题,所以只需要使用表单提交选项。

非常感谢你的帮助。

**Controller :**

@Controller
public class ReportsController {

    @Resource(name = "meetingDao")
    private MeetingDao meetingDao;


    @RequestMapping(value="/ReportPage")
    @Secured({"ROLE_HOME"})
    public String reportPage(HttpServletRequest request, HttpSession session, ModelMap model) {
        List<Meeting> meetings = meetingDao.getMeetings();
        model.addAttribute("command", new ReportsForm());
        model.put("pickListMeetings",meetings);
        return "ReportPage";
    }


    @RequestMapping(value = "/processReport")
    @Secured({"ROLE_HOME"})
    public String processReport(@ModelAttribute ReportsForm form, HttpServletRequest request, ModelMap modelMap, Principal principal) {
        String meeting = form.getSelectedMeeting();

        System.out.println("The Meeting----:"+form.getSelectedMeeting());// is null 

          try {        
              Vector v = PersonFactory.getInstance().getPeople( ds );         
          if (v.size() == 0) {               
              System.out.println("Invalid user id to send Email");
            } else {
                CGDSPerson p = (CGDSPerson) v.get(0);
                emailReport = p.getEmailId();
                System.out.println("Email report to  = "+emailReport);              
            }
        } catch (Exception e) {
            e.printStackTrace();

        }
        ....there is some code in here ...

        modelMap.addAttribute("command", new ReportLocation(location, "/bt/ReportPage.htm"));

        return "DisplayReport";

    }
}


**ReportPage.jsp**
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

<span style="display: inline-block; align: center; width: 475px; vertical-align: top;">
    <div align="center">
        <img src="spacer.gif" style="padding: 0px; margin: 0px; border: none; width: 1px; height: 80px;"/>
        <br>

<form:form method="POST" style="margin-bottom:0;">

  <table width="100%" cellpadding="0" cellspacing="0" border="0" class="BorderMain">
  <tr>
  <td align="left" valign="top">
  <fieldset>
    <legend>Attendance Report :</legend>  
    <br> 
    <table align="center" width="100%" border="0"> 
    <tr>
    <td align="right" width="25%">
      Select a report : 
    </td>
    <td align="left" width="50%">
      <form:select path="selectedMeeting" id="selectedMeeting">
    <form:options items="${pickListMeetings}" itemValue="meetingId"
        itemLabel="name" />
    </form:select>

    </td>
    <td align="right" width="25%">
      <a href="#" class="fg-button ui-state-default fg-button-icon-left ui-corner-all" onclick="submitContainerNoReport()" id="reportPrint">
        <span class="ui-icon ui-icon-print"></span>Print report 
      </a>
    </td>
    </tr>
    </table>
    <br>
    </fieldset>
    </td>
  </tr>
  </table>

 </form:form>

        <hr>
    </div>
</span>             

<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">

$(function() {
    $("#selectedMeeting").focus();
    $("#selectedMeeting").prepend("<option value=''>--- Select a Meeting ---</option>");
    $("#selectedMeeting").val('').prop('selected', true);
});

function submitContainerNoReport()
{
    formSubmit('/bt/processReport.htm');    
}

</SCRIPT>



**ReportForm.java**

public class ReportsForm extends RemanForm {

    private String selectedMeeting;

    /**
     * @return the selectedMeeting
     */
    public String getSelectedMeeting() {
        return selectedMeeting;
    }

    /**
     * @param selectedMeeting the selectedMeeting to set
     */
    public void setSelectedMeeting(String selectedMeeting) {
        this.selectedMeeting = selectedMeeting;
    }

}

0 个答案:

没有答案