This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • How to display a Flash movie (from a byte array)
Skip to end of metadata
Go to start of metadata

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 is a resource with the appropriate markup around it.  The general idea is that you want to make some 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 have such a class made, there are a couple of things to do. 

One, you must implement onResourceRequested, this will write the flash bytes into the resource stream, and might look something like this:

public void onResourceRequested() {
        getRequestCycle().setRequestTarget(new IRequestTarget() {
            public void respond(RequestCycle requestCycle) {
                requestCycle.getResponse()getOutputStream().write(getFlashByteArray());
            }
        });
    }

You may override onComponentTag to dynamically output the height and width of the Flash movie

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:

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
        flashBuffer.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, flashBuffer);
    }

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, to look like this:

        <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>

 And that is basically all that is required to display your flash movie that might be stored as a byte array in a database somewhere!