1

My web application is written in Java (backend). It uses the Spring Framework.

Now when my Controller returns the model to frontend jsp, I want to obtain some values from it's Hashmap.

For this I use the libraries of JSTL and Expression Language.

<c:if test="${not empty model.ladungstraegerNummer}">
                    yadcf.exFilterColumn(oTable, [[3, ['
                    <c:out value="${model.ladungstraegerNummer}"/>
                    ']]]);
                    </c:if>

First I check if the variable is empty (sometimes it is) and after that it is written into Javascript code (yadcf is a Filter extension on top of jQuery and Datatables).

The result of the c:out should look like this:

yadcf.exFilterColumn(oTable, [[3, ['WNC402']]]);

The apostrophes are important. My code output is:

yadcf.exFilterColumn(oTable, [[3, ['
                             WNC402
                             ']]]);

Somehow Javascript doesn't accept this String.

I edited my question, because it was faulty. The c:out worked and the apostrophes we're at the right place. I think I had some whitspace in my String, so that the JS function could not use it.

Oskar Westmeijer
  • 119
  • 1
  • 1
  • 13
  • The apostrophes are out of the c:out tag, directly in the JSP code. So it has nothing to do with c:out. – JB Nizet Sep 01 '17 at 08:55

2 Answers2

0

Try below one :

<c:if test="${not empty model.ladungstraegerNummer}">
                        yadcf.exFilterColumn(oTable, [[3, [
                        <c:out value="'${model.ladungstraegerNummer}'"/>
                        ]]]);
                        </c:if>

JB Nizet's above comment makes sense.

Alin
  • 314
  • 1
  • 3
  • 9
0

I formated my code, it looks now like this. I removed some whitespaces.

      <c:if test="${not empty model.ladungstraegerNummer}">
         yadcf.exFilterColumn(oTable, [[3, ['<c:out value="${model.ladungstraegerNummer}"/>']]]);
      </c:if>

output:

yadcf.exFilterColumn(oTable, [[3, ['WNC402']]]);

Thank you for your effort guys.

Oskar Westmeijer
  • 119
  • 1
  • 1
  • 13