How to trigger the specific controller action using a button?

Posted by Eugene on Stack Overflow See other posts from Stack Overflow or by Eugene
Published on 2012-09-03T20:46:08Z Indexed on 2012/09/03 21:38 UTC
Read the original article Hit count: 145

Filed under:
|
|
|

I'm creating a simple training project. I've implemented a controller method, which deletes an item from the list. The method is looking like this:

@Controller
@RequestMapping(value = "/topic")
public class TopicController {

    @Autowired
    private TopicService service;

    ...

    @RequestMapping(value = "/deleteComment/{commentId}", method = RequestMethod.POST)
    public String deleteComment(@PathVariable int commentId, BindingResult result, Model model){

        Comment deletedComment = commentService.findCommentByID(commentId);
        if (deletedComment != null) {
            commentService.deleteComment(deletedComment);
        }

        return "refresh:";
   }

}

This method is called from the button-tag, which is looking in the following way:

_form> _button formaction = "../deleteComment/1" formmethod = "post">delete_/button> _/form>

Sorry, but in the form tag I've changed all the '<' characters with the '_', because the tag was invisible. In my project the form-tag is looking like a cliuckable button. But there is a serious problem: controller's method is never triggered. How can I trigger it, using a button-tag?

P.S. the call is performed from the page with URI http://localhost:8080/simpleblog/topic/details/2 and controller's URI is the http://localhost:8080/simpleblog/topic/deleteComment/2

© Stack Overflow or respective owner

Related posts about java

Related posts about spring