T
T
Tatyana Khomyakova2017-06-17 22:00:43
Spring
Tatyana Khomyakova, 2017-06-17 22:00:43

freemarker. How to send array to controller?

On the page, the user dynamically adds fields, you need to collect data from the input into objects, then into an array and send it to the controller. I tried to do this: first on get we put an empty array in map
cb768a0798c24f3788f1d1ae1fea7c0e.png
Then on the page I try to access the sheet using the freemarker. 61dc811f23f14d8ca68ad243ba8f5083.png
An error is thrown, as I understand it, because the array is empty and I'm trying to access a non-existent element.
Get guess like this: 01d3bcfd30f049178e7934fd0ae89132.png
How can I dynamically add an object to an array on a page?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Frozen Coder, 2017-06-18
@frozen_coder

The option is this, freemarker has #list , we display what we have through it. We form new list elements that need to be inserted on the page using jQuery and add them to the page where necessary, when necessary (by pressing a button or as you have).
An example of how to form and insert a new block from to... .
Moreover, in the code of the generated new elements there will be no free marker (as you have in the example in the value attribute). When forming, do not forget to calculate the index in the name attribute for new elements. Well, the id of the inserted elements must be unique. Somehow, try it.
Z.Y. For the future, the code should not be inserted through screenshots - here you can insert it with highlighting and formatting through the code tag.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question