I have an object field with person\'s last name.
If I use ${person.lastName}, I get O\'Brian
If I use
You could define a new EL function that escapes strings for you.
E.g.
In Java
public class MyStringUtil {
public static String escapeJs( String str )
{
// escape the string (e.g. replace ' with \')
}
}
In a tag library descriptor file:
<function>
<name>escapeJs</name>
<function-class>package.to.MyStringUtil</function-class>
<function-signature>
java.lang.String escapeJs( java.lang.String )
</function-signature>
</function>
Then in your JSP (assuming you've included your .tld
with a prefix of foo
:
<a href="#"
class="delete"
onclick="if(confirm('${foo:escapeJs(person.lastName)}' + _('Are you sure you want to delete this application?'))) {deleteApplication('${application.identifier}')};return false;"><bean:message key="application.delete"/></a>
Store it as O'brian in the database, but before displaying it do a find replace to convert any ' to \'