wicket4-webjars-parent

Parent POM for wicket4-webjars

License

License

Categories

Categories

Wicket User Interface Web Frameworks
GroupId

GroupId

com.mpobjects.wicket
ArtifactId

ArtifactId

wicket4-webjars-parent
Last Version

Last Version

2.0.4
Release Date

Release Date

Type

Type

pom
Description

Description

wicket4-webjars-parent
Parent POM for wicket4-webjars
Project URL

Project URL

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

Project Organization

MP Objects
Source Code Management

Source Code Management

https://github.com/mpobjects/wicket4-webjars.git

Download wicket4-webjars-parent

How to add to project

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

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

  • library
  • samples

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