0

I am using the DataTables for viewing data in table form. I am sending the data as a list of objects from the backend(JAVA). I need to retrieve the object Ids as a single string on front end and iterate on them.

For that, in iteration of the data I have concatenated the id with a separator, as

<c:set var="tagIds" value="${tag.id},${tagIds}"/>

The id String is created, what I thought - but I cant use in the JavaScript

In Javascript, I declared a variable as follows

var tagIds = ${userId};

this reflects that Syntax error. This assumes that after comma(,) it is a new variable. I am unable to pass that variable.

Also, I tried sending these values as parameter in javascript function call, but resulting in the same error.

saveTags(${userId}); & saveUploadedTags(<c:out value='${userId}'/>);

Result

Error:
SyntaxError: identifier starts immediately after numeric literal 
saveTags(4028808241a34ba60141a35049380000)
Termininja
  • 6,620
  • 12
  • 48
  • 49
sdfhdsh
  • 1
  • 4

1 Answers1

0

You have to make sure that the resulting JavaScript code is valid, as you yourself noted:

var tagIds = "${userId}";

Now that's not necessarily the safest thing to do if you're not 100% sure of the contents of the stuff making up the id string. The best thing to do would be to use a JSON encoder; as far as I know there isn't one built into the standard JSTL/EL set of functions, but there are many available on the web.

Pointy
  • 405,095
  • 59
  • 585
  • 614