2014-11-14 91 views
0

什么即时试图是一个简单的布尔值写入隐藏字段的JSP中的值写入到从控制器:如何使用POST方法

控制器:

@RequestMapping(value = "/createResource", method = RequestMethod.POST) 
public String createCategory(@RequestParam("parentCategory") String parentCategory,      
          @ModelAttribute("SmartResources") Category category, ModelMap model, HttpSession session) 
{ 
    model.addAttribute("resourceProperties", CategoryPropertyService.getInstance().getAllPropertiesById(Integer.parseInt(parentCategory))); 

    model.addAttribute("test", Boolean.TRUE); 

    return "redirect:" + GlobalConstants.Dialog.DIALOG_BLANK; 
} 

JSP:

<input type="hidden" id="showPopUp" name="showPopUp" value="${test}" />  

当我读与jQuery隐藏输入其总是空值:

脚本:

var popUpControl = $("#showPopUp").val(); 
var modal = $.UIkit.modal("#newResource"); 
if (popUpControl == true) { 
    modal.show(); 
} 

当我做同样的在同一个控制器的输入域得到填补的GET方法。

请帮帮我。必须有一种方法来填写post方法中的输入字段。

回答

1

如果你想从模型的属性跨越重定向坚持,你将不得不使用模型界面的专业化,RedirectAttributes

@RequestMapping(value = "/createResource", method = RequestMethod.POST) 
public String createCategory(@RequestParam("parentCategory") String parentCategory,      
          @ModelAttribute("SmartResources") Category category, ModelMap model, RedirectAttributes redirectAttrs, HttpSession session) 
{ 
    redirectAttrs.addFlashAttribute("resourceProperties", CategoryPropertyService.getInstance().getAllPropertiesById(Integer.parseInt(parentCategory))); 

    redirectAttrs.addFlashAttribute("test", Boolean.TRUE); 

    return "redirect:" + GlobalConstants.Dialog.DIALOG_BLANK; 
} 
+0

感谢这个嗨。现在我有antoher问题。我总是得到这个错误:客户端发送的请求在语法上不正确()。 – 2014-11-14 12:58:11

+0

保留modelMap中的参数than,编辑答案 – 2014-11-14 13:13:10

+0

找到它。这是布尔值。用一个字符串替换它,语法是正确的。仍然js部分从“测试”属性没有价值 – 2014-11-14 13:41:31