spring

0

Witajcie,

Usiłuję zrobić prosty przycisk, który będzie zapisywac wpisane slowa z pola tekstowego do listy <>, a po przejsciu do /results wyswietli mi te wprowadzone dane.

<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<BODY>

<form action="#" th:action="@{/}" th:object="${achievement}" method="post">
    <input type="text" th:field="*{name}"/>
    <input type="submit" name="action" value="save" />
    <input type="submit" name="action" value="show" />

</form>

<table style="width:0%">
    <tr>
        <th>name</th>
    </tr>
    <tr>
        <td>Jill</td>
    </tr>
    <tr>
        <td>Eve</td>
    </tr>

</table>
</BODY>
</html>

@Entity
public class Achievement {
    @Id
    @GeneratedValue
    private Long id;

    private String token;

    @GeneratedValue
    @Column(nullable = false)
    private String name;

    private String description;

    public Achievement(String name) {

        this.name = name;
    }

    @ManyToOne
    private Game game;

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public Long getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Game getGame() {
        return game;
    }

    public void setGame(Game game) {
        this.game = game;
    }
}
@Controller
@RequestMapping("/")
public class Controler {

    @Autowired
    private Manager manager;

    @GetMapping("/")
    public String greeting(@RequestParam(name="name", required=false, defaultValue="World") String name, Model model) {
        model.addAttribute("name", name);
        return "main";
    }

    @RequestMapping(value="/", method = RequestMethod.POST)
    public String greetingSubmit(@ModelAttribute Achievement achievement, HttpSession session) {
        String names = (String) session.getAttribute("names");
        if (names == null) {
            session.setAttribute("names", names);
        }
        manager.getAchievementList().add(new Achievement(names));
        return "main";
    }
}

@RestController
public class ResControler {

    @Autowired
    private Manager manager;

    @GetMapping("/results")
    public List<Achievement> achievementList() {
        return manager.getAchievementList();
    }
}

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Fri Jun 07 13:12:04 CEST 2019
There was an unexpected error (type=Internal Server Error, status=500).
Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "main" - line 10, col 24)

Co jest źle?
0

Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "main" - line 10, col 24)

Masz błąd w szablonie main w linijce 10 w 24 znaku.

Z tego co widzę to prawdopodobnie dwa inputy z submit

0

Wywaliłem na chwilę i dalej nic :(

0
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<BODY>
<form action="#" th:action="@{/}" th:object="${achievement}" method="post">
    <input type="text" th:field="*{name}"/>
    <input type="submit" name="action" value="save" />
    <input type="submit" name="action" value="show" />
</form>
</form>
</BODY>
</html>

troszke posprzatalem

0

uppss, poprawilem

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<BODY>
<form action="#" th:action="@{/}" th:object="${achievement}" method="post">
    <input type="text" th:field="*{name}"/>
    <input type="submit" name="action" value="save" />
    <input type="submit" name="action" value="show" />
</form>
</BODY>
</html>

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Fri Jun 07 1635 CEST 2019
There was an unexpected error (type=Internal Server Error, status=500).
Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "main" - line 9, col 24)

1 użytkowników online, w tym zalogowanych: 0, gości: 1