Call spring service from inline javascript

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Call spring service from inline javascript

Hi! I've veen developing an application with Spring and Thymeleaf.
I know you can call methods on registered beans over the components like this:

<option th:each='colony: ${@addressService.searchColoniesByPostal(04400)}' th:value='${colony.postalCode}' th:text='${}'></option>"

This code will return all the elements to display in each option of the select element.

Now the question, I've trying to set the value 04400 reading it from another field without success.
So I need to populate the combo, based on the input of another field.

How can I pass the value from the input field as a param of my service invocation?

I've tried javascript scape, like this:

<script th:inline="javascript">
                function setColony(element){
                        var colony = '04400';
                        var json = /*[[${@direccionService.buscarColoniasPorCP(colony)}]]*/;
But it isn't replacing the value for colony and it's returning and empty array:

var json = [] cause the var could not be replaced.

What can I do to achieve this?