I have a simpleformController which needs to handle request get and post both. While gets the user needs to be redirected to login screen which works fine if handlerequest is used but onSubmit does not get called while posting the page?? Any idea why?
I have tried changing the handlerequest to a private void method displayForm and called it from formBackingObject method which works fine while get and also calls the onSubmit method correctly as required.
But only problem is while calling displayForm a private void method I am unable to redirect the page to login as formBackingObject method does not have reponse object nor i can use return ModelView from private method displayForm as formBackingObject returns Object.
@Override
protected Object formBackingObject(HttpServletRequest request) throws Exception {
if (logger.isDebugEnabled()) {
logger.debug("In formBackingObject()... ");
}
Object obj = request.getSession().getAttribute(CURRENT_FORM);
if (obj != null) {
if (logger.isDebugEnabled()){
logger.debug("update profile details form already exist, returning...");
}
return obj;
}
MyForm Form = new MyForm();
request.getSession().setAttribute(CURRENT_FORM, Form);
displayForm(request);
return Form;
}
Original method: does not allow post to be handle by onSubmit
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
mv = new ModelAndView(new RedirectView(request.getContextPath() + "login.htm"));
RequestCache requestCache = new HttpSessionRequestCache();
requestCache.saveRequest(request, response);
mv.addObject("c_name",getPManager().getCName());
request.getSession().setAttribute("login_from_pac","yes");
return mv;
}
New method: To load form, but user should be forced to login (redirected to login if login is correct user can see this form) before coming to this form. This method is called from formBackingObject method to load the form but does not have response object for redirection to login page. Following method does not work
private void displayForm(HttpServletRequest request) throws Exception {
HttpServletResponse response = null; -->
ModelAndView mav = null;
mav=new ModelAndView(new RedirectView(request.getContextPath() + "login.htm"));
RequestCache requestCache = new HttpSessionRequestCache();
requestCache.saveRequest(request, response);
//mav.addObject("c_name",getPManager().getCName());
request.getSession().setAttribute("c_name", getPManager().getCName());
request.getSession().setAttribute("login_from_pac","yes");
//return mav;
}
Hi i could finally redirect to login page before reaching the main page call. I override isFormSubmission and used showForm instead of handlerequest or any private method called from formBackingObject. Heres the code
return successview
}