You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Joe Hudson <Jo...@clear2pay.com> on 2009/08/31 14:08:27 UTC
is it possible to include script resources using the
HeaderContributor above the WebPage component script references
Hello, I would like for the script included using a HeaderContributor to be above <script> references within the WebPage component head node. Is this possible. The reason I would like to do this is because I would like to be able to reference code from the script file which is included using the HeaderContributor. For example:
--- Application class ---
// inside init method
addComponentInstantiationListener(new IComponentInstantiationListener() {
public void onInstantiation(Component component) {
if (component instanceof WebPage) {
component.add(new HeaderContributor(new IHeaderContributor() {
public void renderHead(IHeaderResponse response) {
response.renderJavascriptReference(new JavascriptResourceReference(MyReferenceClass.class, "scripts/example.js"));
}
}));
}
}
});
// WebPage component template
<head>
<script type="text/javascript">
...
// I can't reference anything from the scripts/example.js because the source reference appears below this in the rendered output
</script>
</head>
By the way, please tell me if this is bad code and there is a better way as I am very new to Wicket. All code criticism is welcomed :)
Thanks.
Joe
Re: is it possible to include script resources using the
HeaderContributor above the WebPage component script references
Posted by Major Péter <ma...@sch.bme.hu>.
This could be helpful for you for first step:
http://cwiki.apache.org/WICKET/markup-inheritance.html
Regards,
Peter
Joe Hudson írta:
> Hello, I would like for the script included using a HeaderContributor to be above <script> references within the WebPage component head node. Is this possible. The reason I would like to do this is because I would like to be able to reference code from the script file which is included using the HeaderContributor. For example:
>
> --- Application class ---
> // inside init method
> addComponentInstantiationListener(new IComponentInstantiationListener() {
> public void onInstantiation(Component component) {
> if (component instanceof WebPage) {
> component.add(new HeaderContributor(new IHeaderContributor() {
> public void renderHead(IHeaderResponse response) {
> response.renderJavascriptReference(new JavascriptResourceReference(MyReferenceClass.class, "scripts/example.js"));
> }
> }));
> }
> }
> });
>
> // WebPage component template
> <head>
> <script type="text/javascript">
> ...
> // I can't reference anything from the scripts/example.js because the source reference appears below this in the rendered output
> </script>
> </head>
>
> By the way, please tell me if this is bad code and there is a better way as I am very new to Wicket. All code criticism is welcomed :)
>
> Thanks.
>
> Joe
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: is it possible to include script resources using the
HeaderContributor above the WebPage component script references
Posted by Pedro Santos <pe...@gmail.com>.
Joe, an diferent option is create a custom WebPage with all needed resources
to serve as super class for all web pages class of your application.
Html for super class:
<html >
<head>
<wicket:link>
<script type="text/javascript" src="scripts/example.js"></script>
</wicket:link>
</head>
<body>
<wicket:child />
</body>
</html>
and for subclasses
<head>
</head>
<body>
<wicket:extend>
<!-- page code -->
</wicket:extend>
</body>
</html>
On Mon, Aug 31, 2009 at 9:08 AM, Joe Hudson <Jo...@clear2pay.com>wrote:
> Hello, I would like for the script included using a HeaderContributor to be
> above <script> references within the WebPage component head node. Is this
> possible. The reason I would like to do this is because I would like to be
> able to reference code from the script file which is included using the
> HeaderContributor. For example:
>
> --- Application class ---
> // inside init method
> addComponentInstantiationListener(new
> IComponentInstantiationListener() {
> public void onInstantiation(Component component) {
> if (component instanceof WebPage) {
> component.add(new HeaderContributor(new
> IHeaderContributor() {
> public void renderHead(IHeaderResponse
> response) {
> response.renderJavascriptReference(new
> JavascriptResourceReference(MyReferenceClass.class, "scripts/example.js"));
> }
> }));
> }
> }
> });
>
> // WebPage component template
> <head>
> <script type="text/javascript">
> ...
> // I can't reference anything from the scripts/example.js
> because the source reference appears below this in the rendered output
> </script>
> </head>
>
> By the way, please tell me if this is bad code and there is a better way as
> I am very new to Wicket. All code criticism is welcomed :)
>
> Thanks.
>
> Joe
>