Search code examples
jqueryjspstruts2jquery-templatesognl

Using jQuery Templates in Struts2


I am attempting to update a page using Struts2 (using jOWL to display an ontology). The original HTML page uses jQuery templates, having several lines such as:

<h2 class="propertybox title" data-jowl="rdfs:label">${rdfs:label}</h2>
<span class="alt">${?p}</span><span>: </span><span>${?t}</span>

to display a variable determined in a jQuery script file. This works well enough as a .html file. However, the .jsp file thinks I am attempting to use Struts variables rather than a jQuery template. It crashes when it encounters the colon and question mark.

I did find some jQuery Struts2 libraries, but I didn't see any tags that would map to jQuery templates. Is there another way to do this?


Solution

  • Your issue is that a jsp thinks ${} is EL. So you need to somehow escape part of the express, this isn't going to be pretty:

    From the JSP 2 spec:
    
    For literal values that include the character sequence ${, JSP 2.0 provides a
    way to escape them by using the sequence ${'${'. For example, the following
    character sequence is translated into the literal value ${expr}:
    
    ${'${'}expr}
    

    Source: http://www.velocityreviews.com/forums/t129212-ot-jsp-escape-el-expressions.html