When incorporating Boolean conditions in JavaScript with Thymeleaf using th:inline="javascript"
, an exception is thrown which appears as follows:
org.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 22; The entity name must immediately follow the '&' in the entity reference.
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:441)
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1436)
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEntityReference(XMLDocumentFragmentScannerImpl.java:1845)
.............................
The provided JavaScript code snippet is displayed below:
<script type="text/javascript" th:inline="javascript">
$(document).ready(function(){
$('.fancybox').fancybox({
'width' :'623px',
'maxHeight':'156px'
});
var catId = $("#category").val();
if(catId != null && catId != ''){
findSubCategories();
/*<![CDATA[*/
var subCatId = /*[[${searchProductDto.subCategory}]]*/
/*]]>*/
debugger;
if(subCatId != null){
$("#subCategory").val(subCatId);
}
}
});
...............................
How can we properly use the & operator in Thymeleaf?