Spring RequestParam

i have a form, which has an array wiht ints. i want to add an int to this forms array.
@PostMapping(path = "/a")
String addEntry(@Valid @ModelAttribute("form") Form form, Errors errors, Model model,
@RequestParam(value = "id", required = false, defaultValue = "0") int id) {

if (id != 0) {
form.add(id);
return mainMapping(model, form); // is the get mapping for /a
// return "a";????
}
form.toNewEntry();
return "redirect:/b";
}
@PostMapping(path = "/a")
String addEntry(@Valid @ModelAttribute("form") Form form, Errors errors, Model model,
@RequestParam(value = "id", required = false, defaultValue = "0") int id) {

if (id != 0) {
form.add(id);
return mainMapping(model, form); // is the get mapping for /a
// return "a";????
}
form.toNewEntry();
return "redirect:/b";
}
Form
public void add(int id) {
List<Integer> arr = getAlleys();

if (arr.contains(id)) {
return;
}
arr.add(id);
setAlleys(arr);
System.out.println(getAlleys()); // [1]
}

Model toNewEntry() {
Model entry = Model();
System.out.println(getAlleys()); // []
entry.setAlleys(getAlleys());
return entry;
}
public void add(int id) {
List<Integer> arr = getAlleys();

if (arr.contains(id)) {
return;
}
arr.add(id);
setAlleys(arr);
System.out.println(getAlleys()); // [1]
}

Model toNewEntry() {
Model entry = Model();
System.out.println(getAlleys()); // []
entry.setAlleys(getAlleys());
return entry;
}
why is the array empty in the tonewentry func?
6 Replies
JavaBot
JavaBot11mo ago
This post has been reserved for your question.
Hey @' .• KIΛ.RΛR ’•. '! Please use /close or the Close Post` button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
' .•` KIΛ.RΛR ’•. '
like idk hgow do i add things to the form without reloading the site and therefore resetting the form?
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
' .•` KIΛ.RΛR ’•. '
nope :/
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
JavaBot
JavaBot11mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server