Hi all, I am trying to solve this problem:
I got a portlet with different method
main method is a rendermapping
}Code:@RenderMapping public String showMovies(RenderRequest request, RenderResponse response, Model model) throws IOException{ model.addAttribute("movies",movieService.getAll()); return "movies/index"
in my index.jsp i got a renderurl to
and the relative showAddMovieForm.jspCode:@RenderMapping(params={"action=showAddMovieForm"}) public String addMovieForm(RenderRequest request, RenderResponse response, Model model) throws IOException{ System.out.println("method: " + new Object(){}.getClass().getEnclosingMethod().getName()); model.addAttribute("movie", new Movie()); return "movies/showAddMovieForm"; }
when i send the form the actionurl is handled byCode:// CUT ... <portlet:renderURL var="addMovieUrl" escapeXml="false"> <portlet:param name="action" value="addMovie" /> </portlet:renderURL > <form:form modelAttribute="movie" method="POST" action="${addMovieUrl}" htmlEscape="false" > <table> <tr> <td><form:label path="title">Title:</form:label></td> <td><form:input path="title"/> <form:errors path="title" cssClass="error"/></td> </tr> </table> <input type="submit" value="Add" /> </form:form> // CUT ...
automatically after the actionmapping annotated method the showMovies method si automatically calledCode:@ActionMapping(params={"action=addMovie"}) public void addMovie( @ModelAttribute("movie") Movie movie, BindingResult result, ActionRequest request, ActionResponse response) throws IOException{ movieValidator.validate(movie, result); if(result.hasErrors()){ logger.error("result has errors"); return; <-------------------------------------------- here i want to come back to showAddMovieForm (when it displays the error), and i want to do that avoding the annotation of this method in a rendermapping method }else{ logger.debug("result is error free"); } movieService.add(movie); logger.debug("movie " + movie.getTitle() + " added" ); }
someone have any idea how to solve this problem (read into the code of the last block) ?
thanks a lot
ps
this is how I can solve the problem using a rendermapping annotated method:
Code:@RenderMapping(params={"action=addMovie"}) public String addMovie( @ModelAttribute("movie") Movie movie, BindingResult result, RenderRequest request, RenderResponse response, Model model) throws IOException{ movieValidator.validate(movie, result); if(result.hasErrors()){ logger.error("result has errors"); return "movies/showAddMovieForm"; }else{ logger.debug("result is error free"); } movieService.add(movie); logger.debug("movie " + movie.getTitle() + " added" ); model.addAttribute("movies",movieService.getAll()); return "movies/index"; }


Reply With Quote
