Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsp 正在重置Spring MVC表单对象_Jsp_Spring Mvc_Liferay 7 - Fatal编程技术网

Jsp 正在重置Spring MVC表单对象

Jsp 正在重置Spring MVC表单对象,jsp,spring-mvc,liferay-7,Jsp,Spring Mvc,Liferay 7,我使用SpringMVC表单来构造我的jsp表单,我使用Model属性来向jsp和控制器传递数据 @RenderMapping(params ="myaction=showDetails") public String showPartnerDetails(@ModelAttribute("reportModel") ReportSettingModel reportModel,RenderRequest req, RenderResponse res,ModelMap map){

我使用SpringMVC表单来构造我的jsp表单,我使用Model属性来向jsp和控制器传递数据

@RenderMapping(params ="myaction=showDetails")
public String showPartnerDetails(@ModelAttribute("reportModel") ReportSettingModel reportModel,RenderRequest req, RenderResponse res,ModelMap map){
        List<String> reportsList=portalService.getReportsList();
        reportModel.setReportDisplayName(reportsList);
        reportModel.setComments("Test");
        map.addAttribute("reportModel", reportModel);
}
我的问题是,从控制器类中的一个方法开始,我正在构造这个完整的模型对象,并使用ModelMap将其发送到JSP,我成功地接收到这个模型属性,并在从控制器发送的JSP页面中使用它

@RenderMapping(params ="myaction=showDetails")
public String showPartnerDetails(@ModelAttribute("reportModel") ReportSettingModel reportModel,RenderRequest req, RenderResponse res,ModelMap map){
        List<String> reportsList=portalService.getReportsList();
        reportModel.setReportDisplayName(reportsList);
        reportModel.setComments("Test");
        map.addAttribute("reportModel", reportModel);
}

这种行为是意料之中的。Spring的工作方式与您描述的不同。您放入模型中的数据不会在会话或其他内容中持久化

所发生的事情是,当您填充模型时,它将被发送到JSP。JSP将使用数据来呈现表单并填充所有字段,模型将“丢失”。当您点击submit时,所有字段都被收集到服务器,服务器将根据请求数据组合成一个模型对象。请求中没有的内容将不在模型中

如果要保留某些值,需要使用表单中的隐藏字段将其放入提交请求中。当然,以这种方式“保存”的数据量是有限的。通常,您通过这种方式保存一些ID,因为您不希望用户看到它们,但可能需要它们来提取一些数据

枚举,值列表。。。他们需要经常换新衣服。如果要选择此选项,请在服务层上使用缓存

@RenderMapping(params = "myaction=getreportSetup")
    public String getReportSetup(@ModelAttribute("reportModel") ReportSettingModel reportModel, RenderRequest req,
            RenderResponse res, ModelMap map){
//here in reportModel, I am getting only data of elements which I have changed in JSP page, but not the fields data which I have calculated in the above showPartnerDetails method
       portalService.getReportFields(req,res,map,reportModel);

}