Custom component: include a JavaScript file once

Hello,

I'm developing a custom component. At the moment my renderer includes with every instance of my component JavaScript code in the body.

Example (Pseudocode):

JSF:

<html>

<body>

<my:component />

<my:component />

</body>

</html>

Current rendered HTML:

<html>

<body>

<input type="text" value="" onClick="function()" />

<script type="text/javascript">function(){}</script>

<input type="text" value="" onClick="function()" />

<script type="text/javascript">function(){}</script>

</body>

</html>

Is there a way to include my JavaScript code once in the header instead of including in the body for every instance.

Target HTML:

<html>

<head>

<script type="text/javascript">function(){}</script>

</head>

<body>

<input type="text" value="" onClick="function()" />

<input type="text" value="" onClick="function()" />

</body>

</html>

Regards

Martin

[1648 byte] By [mwinandya] at [2007-11-27 10:29:36]
# 1

The Tomahawk components do something similar to this and are open source. You might want to take a look to see how they do it.

RaymondDeCampoa at 2007-7-28 17:58:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

The RI commandLink renderer does this as well.At a high level, we track whether or not the supporting JS has been written by a request scope attribute.

rlubkea at 2007-7-28 17:58:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...