1

I have two pages, the first has a form with hidden fields which send parameters to the second one. I want to return an error message if the user go to the second page while the form with hidden fields is empty, so for doing that i tried that but it's not working:

@RequestMapping(value="/generate",method=RequestMethod.POST)
    public String FicheService(@ModelAttribute Movement movement,@RequestParam("nom") String nom, @RequestParam("number") Integer number,ModelMap model){


   if(nom=="" && number == null) { model.addAttribute("errorMessage",true);
                               return "firstPage";
                              }
   else { return "secondPage";}


}           

How to check if @RequestParam is empty or not?

1
  • 1
    You can user @NotEmpty annotation for such validations Commented Jun 4, 2013 at 7:40

1 Answer 1

7

You can specify the @RequestParam, with a required attribute value of false:

@RequestParam(value="nom", required=false)

and then check the null condition the way you have done.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.