Reputation: 5094
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?
Upvotes: 1
Views: 14486
Reputation: 49935
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.
Upvotes: 7