I can't seem to figure out how to implement a form cancel button using an annotated portlet controller. I'm close, but the problem I am having is the canceled changes are still in the form when I come back to it.
This is what my render code looks like
One fix would be to get rid of the check for the containsAttribute in the render code, but then this breaks Save if there is a validation error.Code:@RequestMapping // default render (action=list) public String showEditDefaults(Model model) { if (!model.containsAttribute("editDefaultsCommand")) { EditDefaultsForm editDefaultsCommand = new EditDefaultsForm(); ...init editDefaultsCommand values model.addAttribute("editDefaultsCommand", editDefaultsCommand); } return "edit_defaults"; }
My submit action looks like this
Has anyone figured out how to code a form cancel button on an annotated portlet controller? I pieced together a cancel button from the forum posts for SimpleFormController that did the trick with the now deprecated supressBinding:Code:@RequestMapping(params = "action=save") // action phase public void editDefaultsSubmit(ActionRequest request, ActionResponse response, @ModelAttribute("editDefaultsCommand") EditDefaultsForm editDefaultsForm, BindingResult result, PortletPreferences preferences, SessionStatus sessionStatus) { if (request.getParameter("_cancel") != null) { sessionStatus.setComplete(); response.setPortletMode(javax.portlet.PortletMode.VIEW); } else if (request.getParameter("_save") != null) { new EditDefaultsFormValidator().validate(editDefaultsForm, result); if (!result.hasErrors()) { ...persist values code sessionStatus.setComplete(); response.setPortletMode(javax.portlet.PortletMode.VIEW); } else { response.setRenderParameter("action", "list"); } } }
Is there a similar way to accomplish this with the annotated portlet controller?Code:protected boolean suppressBinding(javax.portlet.PortletRequest request) { return isCancelButton(request); } private boolean isCancelButton(javax.portlet.PortletRequest request) { if (PortletUtils.hasSubmitParameter(request, "_cancel")) { return true; } return false; }
Brad


Reply With Quote