Wicket 1.4 Webjars

Webjars integration for Wicket 1.4. Based on the original wicket-webjar library which provides webjars integration for Wicket 6 and later: https://github.com/l0rdn1kk0n/wicket-webjars

License

License

Categories

Categories

Wicket User Interface Web Frameworks
GroupId

GroupId

com.mpobjects.wicket
ArtifactId

ArtifactId

wicket4-webjars
Last Version

Last Version

2.0.4
Release Date

Release Date

Type

Type

jar
Description

Description

Wicket 1.4 Webjars
Webjars integration for Wicket 1.4. Based on the original wicket-webjar library which provides webjars integration for Wicket 6 and later: https://github.com/l0rdn1kk0n/wicket-webjars
Project URL

Project URL

https://github.com/mpobjects/wicket4-webjars
Project Organization

Project Organization

MP Objects

Download wicket4-webjars

How to add to project

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

Dependencies

compile (3)

Group / Artifact Type Version
org.apache.wicket : wicket jar [1.4,1.4.99]
edu.emory.mathcs.util : emory-util-classloader Optional jar 2.1
org.slf4j : slf4j-api jar 1.7.25

test (3)

Group / Artifact Type Version
junit : junit jar 4.12
org.webjars : jquery jar 2.2.4
javax.servlet : servlet-api jar 2.3

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