This documentation is for an old version of fiftyfive-wicket (2.0.9).


fiftyfive.wicket.js
Class JavaScriptDependency

java.lang.Object
  extended by org.apache.wicket.behavior.AbstractBehavior
      extended by fiftyfive.wicket.js.AbstractJavaScriptContribution
          extended by fiftyfive.wicket.js.JavaScriptDependency
All Implemented Interfaces:
Serializable, IBehavior, IComponentConfigurationBehavior, IClusterable, IHeaderContributor

public class JavaScriptDependency
extends AbstractJavaScriptContribution

Represents a JavaScript file, or group of files, that will be injected into the <head>. This is the mechanism for programmatically declaring JavaScript dependencies within Java code.

There are three ways to use this class:

In all cases, the JavaScript files that you specify will be scanned for dependencies. If any of the files contain sprocket require statements, these requirements will be resolved and added to the <head> as well, in the appropriate order.

For example, let's say you have MyPanel which contains custom JavaScript in an accompanying MyPanel.js file. Your JavaScript in turn depends on jQuery UI. In MyPanel.js you would add this line:

 //= require <jquery-ui>

This informs fiftyfive-wicket-js of the dependency. Then in your Java code, you just need to add MyPanel.js like this:

 public MyPanel(String id)
 {
     super(id);
     add(new JavaScriptDependency(MyPanel.class));
 }

At runtime, fiftyfive-wicket-js will find MyPanel.js, scan it for dependencies, and notice that jQuery UI is needed. It is smart enough to realize jQuery is needed as well. When the page renders, jQuery, jQuery UI, and MyPanel.js will all automatically be included in the <head>, and in the correct order. Futhermore, the necessary jQuery UI CSS will be included as well (the "redmond" theme, by default).

Internally this class delegates to JavaScriptDependencyLocator to find the actual files and their dependencies. The behavior of this dependency discovery can be controlled using the JavaScriptDependencySettings.

Since:
2.0
See Also:
Serialized Form

Field Summary
static JavaScriptDependency JQUERY
          Dependency representing jQuery.
static JavaScriptDependency JQUERY_UI
          Dependency representing jQuery UI.
 
Constructor Summary
JavaScriptDependency(Class<?> cls)
          Creates a JavaScriptDependency for a JavaScript file that accompanies a class of the same name.
JavaScriptDependency(Class<?> cls, String fileName)
          Creates a JavaScriptDependency for a JavaScript file in the classpath, The file name should not include the .js extension.
JavaScriptDependency(String libraryName)
          Creates a JavaScriptDependency for a JavaScript library that resides in the library search path.
 
Method Summary
 void renderHead(IHeaderResponse response)
          Injects the JavaScript files into the <head>, using JavaScriptDependencyLocator to first find the files.
 
Methods inherited from class fiftyfive.wicket.js.AbstractJavaScriptContribution
renderDependencies, renderDomReady
 
Methods inherited from class org.apache.wicket.behavior.AbstractBehavior
afterRender, beforeRender, bind, cleanup, detach, detachModel, exception, getStatelessHint, isEnabled, isTemporary, onComponentTag, onConfigure, onException, onRendered, rendered
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JQUERY_UI

public static final JavaScriptDependency JQUERY_UI
Dependency representing jQuery UI. Automatically injects both jQuery and jQuery UI libraries.


JQUERY

public static final JavaScriptDependency JQUERY
Dependency representing jQuery.

Constructor Detail

JavaScriptDependency

public JavaScriptDependency(Class<?> cls)
Creates a JavaScriptDependency for a JavaScript file that accompanies a class of the same name. For example, a dependency created for MyPanel.class will look for a corresponding file named MyPanel.js in the same classpath location. Simliar to how Wicket locates HTML files, if MyPanel.js cannot be found, the superclass of that panel is searched, and so on.


JavaScriptDependency

public JavaScriptDependency(String libraryName)
Creates a JavaScriptDependency for a JavaScript library that resides in the library search path. The name should not include the .js extension. For example:
 add(new JavaScriptDependency("jquery-ui"));

See Also:
JavaScriptDependencySettings.addLibraryPath(java.lang.Class, java.lang.String)

JavaScriptDependency

public JavaScriptDependency(Class<?> cls,
                            String fileName)
Creates a JavaScriptDependency for a JavaScript file in the classpath, The file name should not include the .js extension. For example:
 add(new JavaScriptDependency(MyPanel.class, "jquery.ui.myplugin"));

Method Detail

renderHead

public void renderHead(IHeaderResponse response)
Injects the JavaScript files into the <head>, using JavaScriptDependencyLocator to first find the files.

Specified by:
renderHead in interface IHeaderContributor
Overrides:
renderHead in class AbstractBehavior


Copyright © 2011 55 Minutes. All Rights Reserved.