In this example, we'll be using the SWFObject from http://blog.deconcept.com/swfobject/.
To begin, lets make sure and copy in our swfobject.js file next to our new AbstractBehavior. And then create our SWFObject.java file like so:
We extend AbstractBehavior and automatically get the ability to override methods that will help us in our cause, i.e. IHeaderContributor and of course IBehavior.
Because we have extended AbstractBehavior, we can add items to the HTML head element by providing our own implementation of renderHeader method:
Here's what we're doing here in a nutshell
- We get a reference to the Response object from our Component
- Grab the id of our HTML element we will be referencing
- Close off the script with the utility method
- In the head tag, you would provide your implementation in renderHead
- Just after our component render, you would override onRendered or rendered as in the code example above
- Just before our component render, you would override onComponentTag
Adding this behavior to our Page
Here's how you would probably add this to your page, in the case of this SWFObject, here's what the HTML most likely would look like
And in our Java code, we provide the following, note the use of Label here, to take advantage of pushing SEO data into the page rather than a messy embed / object call:
Thats all there is to it. Please note that the example above is using Wicket 2.0, but can be easily backported to 1.x. In addition, the full implementation has support for adding parameters and variables which is part of the swfobject.js library.
For the full implementation of the SWFObject behavior please reference this JIRA issue: http://issues.apache.org/jira/browse/WICKET-309