Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5942655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:17:03+00:00 2026-05-22T16:17:03+00:00

I have a simpleformController which needs to handle request get and post both. While

  • 0

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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:17:04+00:00Added an answer on May 22, 2026 at 4:17 pm

    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

    @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) {
                        }
            return obj;
        }
    
        MyForm Form = new MyForm(); 
    
        request.getSession().setAttribute(CURRENT_FORM, Form);
    
    
        return Form;
    }
    
    /**
     * Submit form
     * @param HttpServletRequest
     * @param HttpServletResponse
     * @param Object
     * @param BindException
     * @throws Exception 
     */
    @Override
    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
    
        if (logger.isDebugEnabled()){
        logger.debug("onSubmit");
    }
    
    
    
            ModelAndView mav;
            mav = new ModelAndView("formactivated");
    
            MyForm Form = (MyForm) command;
    
    
            try{                             
    //do logic here
    
                                                        }
    
    @Override
    protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors)throws Exception {
        if (logger.isDebugEnabled()) {
            logger.debug("In showForm ... ");
        }
    
        if(errors.hasErrors()){
            if (logger.isDebugEnabled()) {
                logger.debug("In showForm  has errors... ");
            }
        ModelAndView mav;
        mav = new ModelAndView("formactivated");    
        mav.addAllObjects(errors.getModel());           
        return mav;
        }
    
    
        other login here
    

    return successview
    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SimpleFormController , the doSubmit() is doing nothing but populating a command
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have you managed to get Aptana Studio debugging to work? I tried following this,
How is this done? I have a view which in certain conditions I need
Have a simple console app where user is asked for several values to input.
Have noticed issue while testing iphone app that if one quickly opens/dismisses a modal
I have a form which has a date. I registered a customDateEditor for converting
Have a slight problem. Trying to post XML to a server. To do this,
Have following Java code,that creates StringBuilder with \n,i.e. carriage return delimiters: while (scanner.hasNextLine()){ sb.append(scanner.nextLine()).append(\n);
Have just started to get into CakePHP since a couple of weeks back. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.