Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use spring:message from JavaScript

I have a JQuery function who add a Table in the JSP dynamically:

$('#add').click(function(event) {

    event.preventDefault();

$('.tabela_procurador').before
    ('<table id="tabela_nova' + i + '" class="tabela_nova"> ' +
        '<tr> ' +
            '<td colspan="4" class="subTitulo_barra"> ' +
            '<spring:message code="representante_legal" /> '+ i +' ' +
            '</td> ' +
        '</tr> ' +
      '</table>');
     i++
   });
});

But when i added this table i lost the spring:message.

There is something i can do to jquery recognize this spring:message?

like image 294
Raul Barros Avatar asked May 29 '13 15:05

Raul Barros


1 Answers

As a workaround, put the message value in a hidden input on your jsp page. Then get its value in your javascript. In your case:

<c:set var="val"><spring:message code="representante_legal"/></c:set>
<input id="representante_legal" type="hidden" value="${val}"/>

In your javascript (using jquery) you can then use it as follows:

$('#representante_legal').val()
like image 179
gizit Avatar answered Oct 05 '22 18:10

gizit