powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / новичек в Thymeleaf. Как вернуть параметр
2 сообщений из 2, страница 1 из 1
новичек в Thymeleaf. Как вернуть параметр
    #38749514
SashkaBol
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Полный профан в этой теме, но я разбираюсь как могу.

бин:
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
public class RadioQuestion {
    int id;
    String question;
    List<String> versions;
    String correct;

    public RadioQuestion(int id, String question, List<String> versions, String correct) {
        this.id = id;
        this.question = question;
        this.versions = versions;
        this.correct = correct;
    }

    public int getId() {        return id;    }

    public void setId(int id) {        this.id = id;    }

    public String getQuestion() {        return question;    }

    public void setQuestion(String question) {        this.question = question;    }

    public List<String> getVersions() {        return versions;    }

    public void setVersions(List<String> versions) {        this.versions = versions;    }

    public String getCorrect() {        return correct;    }

    public void setCorrect(String correct) {        this.correct = correct;    }
}



Контроллер:
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
@Controller
public class RadioController {

    private static RadioQuestion rq = null;
    private static String radioChoice = "";

    static {
        List<String> versions = new ArrayList<String>();
        versions.add("eight");
        versions.add("two of course");
        versions.add("more than seven, less than nine");
        versions.add("octopus doesn't have any legs");

        String radioAns = versions.get(1);
        rq = new RadioQuestion(1, "How many legs does a human have:", versions, radioAns);
    }

    @RequestMapping("/radio")
    public String showAllTypes(Model model, String bum){

        model.addAttribute("rq", rq);
        model.addAttribute("radiochoice", radioChoice);

        return "radioquestion";
    }

    @RequestMapping(value="/radio", method= RequestMethod.POST, params = "submit")
    public String submitAswer( RadioQuestion rq){

        System.out.println(rq.getCorrect());

        return "correct";
    }
}



radioquestion.html:
Код: html
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action="#" th:action="@{/radio}" th:object="${rq}" th:method="post">

    <dl>
        <dt th:text="${rq.question}">header</dt>
        <dd th:each="var : ${rq.versions}" >
            <input type="radio"  th:value="${var}" th:field="${rq.id}" />
            <label th:text="${var}">test</label>
        </dd>
    </dl>
    <dd >
        <button type="submit" name="submit" th:text="Submit">submit</button>
    </dd>

</form>



Не могу разобраться как вернуть выбранный ответ (c javascript тоже не очень знаком). Нужна помощь гуру!)
...
Рейтинг: 0 / 0
новичек в Thymeleaf. Как вернуть параметр
    #38749956
mad_nazgul
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
SashkaBolradioquestion.html:
Код: html
1.
2.
3.
<form action="#" th:action="@{/radio}" th:object="${rq}" th:method="post">
...
</form>



Не могу разобраться как вернуть выбранный ответ (c javascript тоже не очень знаком). Нужна помощь гуру!)

А форма куда должна отправляться?!
По моему должно быть: action = "/radio".
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / новичек в Thymeleaf. Как вернуть параметр
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]