views:

193

answers:

1

Hi,

I'm trying to insert a Struts Tiles attribute into a JavaScript function. The JS function is called on load and certain JSP pages should be allowed to append additional code to that function.

The template looks like this:

<html>
<head>
<script>
  function onLoad(){
    ...
    <tiles:insert attribute="html.head.onLoad" ignore="true" />
    ...
  }
</script>
</head>
</html>

And the JSP site that implements this template like this:

<html> 
<head> 
<script>
<tiles:put type="string" name="html.head.onLoad">
        document.getElementById("report").style.height = (getWindowHeight() - 200) + "px";
    </tiles:put>
...
</script>
</head>
</html>

Unfortunately, the attribute is inserted not into the JS function, but somewhere outside in the HTML head.

Do you know a way how I can achieve my goal?

+1  A: 

JS runs at the client side, not at the server side. Tiles runs at the server side, not at the client side. In other words, they doesn't run in the sync as you'd expect from your coding attempt. The server generates HTML/CSS/JS code based on the server side taglibs and then sends it to the client side.

You really need to solve this at the server side. Since the goal is a bit unclear and I don't do Struts/Tiles, I can't go in detail. But you should now at least understand the cause of the problem. Also see this article for more insights.

BalusC
But shouldn't the Struts tile be pasted into the JSP before the JavaScript is run on the client?
Bernhard V