Home > Back-end >  JSTL/AngularJS how to deactivate the expression language for a specific value?
JSTL/AngularJS how to deactivate the expression language for a specific value?

Time:09-10

I have a user interface that let the user enter any value he wants (string value)

The value can contain any characters including {{ and }} such as {{.}} or {{/}}

Example of values

  • text{{.}}here
  • text{{\}}here

I have a jsp page that uses angularjs which displays this value using <c:out value="${stringValue}"/>

The error I have is

angular.js:15697 Error: [$parse:syntax] Syntax Error: Token '.' not a primary expression at column 1 of the expression [.] starting at [.].
https://errors.angularjs.org/1.8.3/$parse/syntax?p0=.&p1=not a primary expression&p2=1&p3=.&p4=.
    at angular.js:138:1
    at AST.throwError (angular.js:16255:1)
    at AST.primary (angular.js:16143:1)
    at AST.unary (angular.js:16121:1)
    at AST.multiplicative (angular.js:16108:1)
    at AST.additive (angular.js:16099:1)
    at AST.relational (angular.js:16090:1)
    at AST.equality (angular.js:16081:1)
    at AST.logicalAND (angular.js:16073:1)
    at AST.logicalOR (angular.js:16065:1)

It's trying to evaluate . in {{.}}

I am finding a solution to deactivate the expression language in the text of the value stringValue so it will appear text{{.}}here without evaluating {{.}}

From what I found, we can deactivate the expression language for the whole jsp page by doing

<%@ page isELIgnored ="true" %> but I want to deactive it only for this value not for the whole page

Any ideas?

CodePudding user response:

<%@ page isELIgnored ="true" %> is not the solution because the error is not in the JSP processing, but in the AngularJS processing.

For example, if you have a JSP page such as

<h1><c:out value="${stringValue}"/><h1>

The JSP will generate an HTML page containing:

<h1>Text{{.}}Text<h1>

Which is interpreted by angularJS, and raises an error.

The solution is to disable the angularJS interpretation, using the directive ngNonBindable. angularJS will not interpret the content of an element with this directive.

<h1 ng-non-bindable><c:out value="${stringValue}"/><h1>
  • Related