0

I'm in a trouble passing EL variable to Javascript with line-breaks.

I have the following calling a Javascript method:

<td>    
    <a href="#" onclick='javascript:deleteClienteObsItem("${clienteObsListElement.codigo}","<fmt:formatDate pattern="dd/MM/yyyy" value="${clienteObsListElement.dataCRM.time}"/>", "${clienteObsListElement.funcionarioIDCRM.nome}","${clienteObsListElement.eventoCRM}","${clienteObsListElement.andamentoCRM}");' data-reveal-id="modalDeleteClienteObs">
        <img src="<c:url value="/resources/Images/Icons/delete.png"/>">
    </a>
</td>

What happens: The deleteClienteObsItem() is not called when the variable contains breaklines.

Edited.

I found a kind of solution: Convert the line-breaks to something them bring it back to line-breaks when I need. But its more like an outline solution than a solution.

Anyone has a real good solution for this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 2
    Encode the string with a JSON encoder. That's really the easiest and most reliable way to deal with situations like this. – Pointy Dec 30 '14 at 15:27
  • @Pointy Do you have an example of this? –  Dec 30 '14 at 16:11
  • @BalusC Sorry about that, was a noob confunsion. –  Dec 30 '14 at 16:11
  • 1
    Well there are various JSON encoding libraries out there; the stock Java server-side environment doesn't include anything for the purpose. – Pointy Dec 30 '14 at 16:17
  • 1
    @Pointy: Apparently not on Java EE 7 yet? Perhaps it's time to move on to new software ;) – BalusC Dec 30 '14 at 16:20
  • 1
    @BalusC well JSON *encoding* is pretty easy to do, depending on what you're trying to encode. A google search for "Java JSON" turns up a bunch of libraries for the purpose. (If you're saying that Java EE 7 *does* have JSON support, that's news to me, but I've got all the JSON support I need already so it's not a big deal.) – Pointy Dec 30 '14 at 16:22
  • I solve this problem in another way! I create some code in back-end to find the data that I was trying to pass throught javascript. But thanks a lot for the answers! :) –  Jan 08 '15 at 12:08

0 Answers0