Reputation: 2628
I have tried
<display:table name="jobTrackerCol" pagesize="20" sort="list" id="data" requestURI="" class="tablelist">
<display:column title="Request Id" sortable="true" ><%-- property="request_id" > --%>
<a href=# onClick="popupSmallWindow('${data.query}');">${data.request_id}</a>
</display:column>
</display:table>
javascript
function popupSmallWindow(query){
//window.location="http://www.continue.com";
myString = query.replace(/[\r\n]/g, "<br />");
alert(myString);
}
value in ${data.query} is long sql query.
I want to display that query in alert or new window when I click on the link.Please guide me on this
Upvotes: 0
Views: 624
Reputation: 691765
First of all, you'll need to JavaScript-escape the query. Indeed, if you query is
select a.id from a where a.name = 'doe'
The resulting HTML code will be:
onClick="popupSmallWindow('select a.id from a where a.name = 'doe'');"
And this will obviously cause problems, because due to the unescaped single quotes, the JS code won't be valid.
You could use apache commons-lang StringEscapeUtils.escapeECMAScript() to do that.
Now, an alert box doesn't display HTML. SO you must not transform \r\n
into <br/>
if you want to display it in an alert box. Leave them as is, and the alert box will display the query just fine.
If you want HTML support, you could use jQuery UI's dialog box to display your SQL query. If you do, then replacing \r\n
with <br/>
would be needed. But you could do that in Java, and place your query in a hidden div that the jquery UI dialog box would use as the content of its dialog box.
Upvotes: 1