Wicket 1.4 Webjars Sample

Sample application of the Wicket 1.4 Webjars integration.

License

License

Categories

Categories

Wicket User Interface Web Frameworks
GroupId

GroupId

com.mpobjects.wicket
ArtifactId

ArtifactId

wicket4-webjars-samples
Last Version

Last Version

2.0.4
Release Date

Release Date

Type

Type

war
Description

Description

Wicket 1.4 Webjars Sample
Sample application of the Wicket 1.4 Webjars integration.
Project Organization

Project Organization

MP Objects

Download wicket4-webjars-samples

How to add to project

<!-- https://jarcasting.com/artifacts/com.mpobjects.wicket/wicket4-webjars-samples/ -->
<dependency>
    <groupId>com.mpobjects.wicket</groupId>
    <artifactId>wicket4-webjars-samples</artifactId>
    <version>2.0.4</version>
    <type>war</type>
</dependency>
// https://jarcasting.com/artifacts/com.mpobjects.wicket/wicket4-webjars-samples/
implementation 'com.mpobjects.wicket:wicket4-webjars-samples:2.0.4'
// https://jarcasting.com/artifacts/com.mpobjects.wicket/wicket4-webjars-samples/
implementation ("com.mpobjects.wicket:wicket4-webjars-samples:2.0.4")
'com.mpobjects.wicket:wicket4-webjars-samples:war:2.0.4'
<dependency org="com.mpobjects.wicket" name="wicket4-webjars-samples" rev="2.0.4">
  <artifact name="wicket4-webjars-samples" type="war" />
</dependency>
@Grapes(
@Grab(group='com.mpobjects.wicket', module='wicket4-webjars-samples', version='2.0.4')
)
libraryDependencies += "com.mpobjects.wicket" % "wicket4-webjars-samples" % "2.0.4"
[com.mpobjects.wicket/wicket4-webjars-samples "2.0.4"]

Dependencies

compile (7)

Group / Artifact Type Version
com.mpobjects.wicket : wicket4-webjars jar 2.0.4
org.apache.wicket : wicket jar [1.4,1.4.99]
org.webjars : jquery jar 1.12.4
org.webjars : jquery-ui jar 1.9.2
org.webjars : bootstrap jar 3.3.7
org.slf4j : slf4j-log4j12 jar 1.7.25
log4j : log4j jar 1.2.17

Project Modules

There are no modules declared in this project.

wicket4-webjars

Integration of webjars for Apache Wicket 1.4. This is a backport of wicket-webjars 2.0.4 to Wicket 1.4.x.

Current build status: Build Status

wicket-webjars dependes on webjars.

Note: This version is only for wicket 1.4.x. This library is mostly forwards compatible. Once you upgrade to Wicket 6 or later you should be able to replace this library with the standard wicket-webjars.

Documentation:

Latest Release

Maven Central

<dependency>
  <groupId>com.mpobjects.wicket</groupId>
  <artifactId>wicket4-webjars</artifactId>
  <version>2.0.4</version>
</dependency>

Installation

  /**
   * @see org.apache.wicket.Application#init()
   */
  @Override
  public void init() {
    super.init();

    // install 3 default collector instances
    // (FileAssetPathCollector(WEBJARS_PATH_PREFIX), JarAssetPathCollector, VfsAssetPathCollector)
    // and a webjars resource finder.
    WebjarsSettings settings = new WebjarsSettings();

    WicketWebjars.install(this, settings);
  }

Usage

Add a webjars resource reference (css,js) to your IHeaderResponse:

public WebjarsComponent extends Panel {

  public WebjarsComponent(String id) {
    super(id);
  }

  @Override
  public void renderHead(IHeaderResponse response) {
    super.renderHead(response);

    response.getHeaderResponse().renderJavascriptReference(new WebjarsJavaScriptResourceReference("jquery/1.12.4/jquery.min.js"));
    response.getHeaderResponse().renderCSSReference(new WebjarsCssResourceReference("bootstrap/3.3.7/css/bootstrap.css"));
  }
}

Or via header contributors:

public WebjarsComponent extends Panel {

  public WebjarsComponent(String id) {
    super(id);
  }

  @Override
  protected void onInitialize() {
    add(JavascriptPackageResource.getHeaderContribution(new WebjarsJavaScriptResourceReference("jquery/1.12.4/jquery.min.js")));
    add(CSSPackageResource.getHeaderContribution(new WebjarsCssResourceReference("bootstrap/3.3.7/css/bootstrap.css")));
  }
}

Add dependencies to your pom.xml:

<dependencies>
  <dependency>
      <groupId>com.mpobjects.wicket</groupId>
      <artifactId>wicket4-webjars</artifactId>
  </dependency>

  <dependency>
      <groupId>org.webjars</groupId>
      <artifactId>jquery</artifactId>
      <version>1.8.3</version>
  </dependency>
</dependencies>

To use always recent version from your pom you have to replace the version in path with the string "current". When resource name gets resolved this string will be replaced by recent available version in classpath. (this feature is available since 0.2.0)

public WebjarsComponent extends Panel {

  public WebjarsComponent(String id) {
    super(id);
  }

  @Override
  public void renderHead(IHeaderResponse response) {
    super.renderHead(response);

    response.render(JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("jquery/current/jquery.js")));
  }
}

SecurePackageResourceGuard

Wicket contains a filter that prevents arbitrarypackage resources from being served. This filter will however break certain webjars packages. For example, webfonts are not included in this filter in wicket 1.4 so you need to add them manually.

In the initialization of your WebApplication simply add the patterns you want to accept

  IPackageResourceGuard packageGuard = getResourceSettings().getPackageResourceGuard();
  if (packageGuard instanceof SecurePackageResourceGuard) {
    SecurePackageResourceGuard secGuard = (SecurePackageResourceGuard) packageGuard;
    secGuard.addPattern("+*.cur");
    secGuard.addPattern("+*.map");

    secGuard.addPattern("+*.svg");

    secGuard.addPattern("+*.eot");
    secGuard.addPattern("+*.ttf");
    secGuard.addPattern("+*.woff");
    secGuard.addPattern("+*.woff2");
  }

Static Linked Resources

In the original wicket-webjars, when running in a Servlet 3+ container you are able to specify URLs like

<img src="webjars/jquery-ui/1.9.2/css/smoothness/images/ui-icons_cd0a0a_256x240.png"/>

This does not work by default in wicket4-webjars, as you are probably not running it in a Servlet 3+ container. In order to make this work you can simply mount an additional IRequestTargetUrlCodingStrategy in your wicket application as follows:

  mount(new WebjarsRequestTargetUrlCodingStrategy());

An alternative method is by using the Servlet 2 setup provided by WebJars.

Note: this functionality is not forwards compatible, as it does not exist in the upstream library.

Limitations

The following functionality from wicket-webjars 2.x is not supported in this backport:

  • CDN

Authors

  • Michael Haitz
  • Martin Grigorov
  • Michiel Hendriks (wicket 1.4.x backport)
com.mpobjects.wicket

MPO

OpenSource Software by MP Objects

Versions

Version
2.0.4