0

I want that the method showEnteredData is executed if the Button is pressed. But it does not execute the function. I thought it should do automaticly. What is the problem? Thanks for your help :=)

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page session="false"%>

    <div id="leer" style="float: left;"></div>
    <div class="filmFilter">
        <form action="articles" method="get">

            <select name="dropdownFilmeFilter">
                <option value="aufsteigend">Preis: aufsteigend</option>
                <option value="absteigend">Preis: absteigend</option>
                <option value="bewertung">Kundenbewertung</option>
                <option value="erscheinungsdatum">Erscheinungsdatum</option>
            </select>

            <input type="submit" value="Done" /> <a href="home">bring me back
                home</a>
        </form>

    </div>

@RequestMapping(value = "/articles")
public String showHome ( Model model){
    List<Article> article = (List<Article>) gd.findAll(Article.class);  
    model.addAttribute("articles", article);


    return "articles";
}


@RequestMapping(value = "/articles", method = RequestMethod.POST)
public String showEnteredData(@RequestParam("dropdownFilmeFilter") String filter, Model model) {
    System.err.println("hohooh");


    List<Article> article = (List<Article>) gd.sortByAttribute(Article.class, "price", true);
    article.clear();

    if (filter == "aufsteigend"){
        article = (List<Article>) gd.sortByAttribute(Article.class, "price", true);
    }
    model.addAttribute("articles", article);

    return "articles";
}

1 Answer 1

3

You can either change the method in your form tag to "post", or change your @RequestMapping's method to RequestMethod.GET. I would recommend the first option.

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

1 Comment

+1 for changing the form to POST - semantically, there's no good reason to use GET for a form, and that has potential to confuse future maintainers (who may or may not be you).

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.