Although Wicket does not provide a Flash component right out of the box, it isn't hard at all to make one using some markup and a Resource. Given a byte array representing a Flash movie, all that is required is to be able to stream this back as is a resource with the appropriate markup around it. The general idea is that you want to make some Component class (component) extending WebMarkupComponent and implementing IResourceListener so that it can be displayed as a component and return a flash movie as a resource to the resource stream.
When You you have such a class made, there are a couple of things to do.
...
Code Block |
---|
public void onResourceRequested() { getRequestCycle().setRequestTarget(new IRequestTarget() { public void respond(RequestCycle requestCycle) { requestCycle.getResponse()getOutputStream().write(getFlashBytesgetFlashByteArray()); } }); } |
You may override onComponentTag to dynamically output the height and width of the Flash movie
Code Block |
---|
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
tag.put("width", WIDTH);
tag.put("height", HEIGHT);
}
|
and finally to ensure that your markup is created correctly to display the Flash, you must override and implement onComponentTagBody as such:
Code Block |
---|
protected void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) { StringBuffer flashBuffer = new StringBuffer(); // in the following, we will append all the necessary body tags of flash markup flashBufferappendflashBuffer.append("<param name=\"movie\" value=\""); // urlFor will provide the link that will stream the flash byte array flashBuffer.append(urlFor(IResourceListener.INTERFACE)); flashBuffer.append("\"/>"); flashBuffer.append("<embed src=\""); flashBuffer.append(urlFor(IResourceListener.INTERFACE)); flashBuffer.append("\" width=\""); flashBuffer.append(WIDTH); flashBuffer.append("\" height=\""); flashBuffer.append(HEIGHT); flashBuffer.append("' quality=\"high\" name=\"movie\" align=\"middle\" plug inspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\">"); replaceComponentTagBody(markupStream, openTag, flashBodyflashBuffer); } |
That is all that is required of the component to provide the Flash resource, and build the body markup. Finally, you want the actual markup (.html) of whoever adds this component (.html), to look like this:
Code Block |
---|
<object wicket:id="WICKET_ID_OF_COMPONENT" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="350" height="100" id="movie" align="middle"> <!-- The markup from onComponentTagBody will go in here --> </object> |
...