Montag, 26. November 2012

Weblets 1.2 and Weblets 1.3

Introduction

Weblets 1.2 recently has been released on MavenCentral, this article is about the new features of the release and an outlook regarding the upcoming Weblets 1.3 release.

Weblets 1.2

Namespace Changes

Weblets 1.2 is the first release hosted on Github after the failed transfer from java.net to Kenai and the first release under a new namespace on Maven Central.

If you want to include Weblets in your program simply now use following entries in your dependencies section.

<dependency>
    <groupId>com.github.weblets</groupId>
    <artifactId>weblets-api</artifactId>
    <version>1.2</version>
</dependency>

and for the implementation use following include 

<dependency>
    <groupId>com.github.weblets</groupId>
    <artifactId>weblets-impl</artifactId>
    <version>1.2</version>
</dependency>

 As you can see the namespace was changed from java.net to com.github.weblets

This change was necessary due to the move to Github, I am sorry about any inconveniences this has caused, but having to move to Github was caused by a problem with the java.net to Kenai transition on Oracles side.

 

New Features

The main new Feature of the 1.2 release is subbundles. Subbundles is a usefule feature if you have multiple text file includes which you want to switch to one single include on the fly.

So how does this work.

First of all you need to define a subbundle in your weblets-config.xml 

<subbundle>
    <id>newBundleId</id>
    <resources>
    /subbundle/script1.js, /subbundle/script2.js
    </resources>
</subbundle>

This defines a new subbundle /bundles/script.js from following resources script1.js and script2.js

Now what happens if one of the scripts is loaded is following, that script1 and script2 are concatenated and loaded within one request, the second request will get a resource already served answer.

You already get a small optimization that way without changing your code between subbundles and normal resource requests.

However by using a small utils function you can cut down on the additional requests if a bundle already is served.

Simply use following:

 <script type="text/javascript" defer="true"
                src="<%=jspweblet.getURL(request, "weblets.demo","/subbundle/script1.js",true)%>">
</script>

<% if (!jspweblet.isResourceLoaded(request, "weblets.demo", "/subbundle/script2.js")) { %>
        <!--
 double includes can be suppressed by the resource loaded
 method, we can add as many includes here as we want the code
 will not be executed for any resource in the bundle
 -->
        <script type="text/javascript" defer="true"
                src="<%=jspweblet.getURL(request, "weblets.demo","/subbundle/script2.js",true)%>">
        </script>
<%}%>

The utils function isResourceLoaded checks whether a resource already is loaded or not. You have this function enabled not only for jsp, but also for jspx and jsf. See the weblets documentation for further information on the utils functions / methods.

By using the utils function you can switch easily between the bundled and non bundled versions of the include.

(Note currently it is not possible to load a bundle from the given subbundle id, this limitation will be lifted in the future)

Weblets 1.3

The main feature of Weblets 1.3 will be finally the connection between JSF 2.x resources and Weblets. What this means is that Weblets will provide its own Resource Handler which allows JSF to access Weblets resource bundles. Along with this feature comes also a set of utility functions which will allow the easy handling of weblets resources on JSF 2.0 level.

Here are examples on what Weblets 1.3 will try to achieve.

<h:graphicImage id="yyy4" value="#{wbl:jsfURL('weblets.demo','/img/icon_alert.gif')}"/>

<h:graphicImage id="yyy5" value="./#{wbl:jsfResource('weblets.demo','/img/icon_alert.gif')}"/>

<h:graphicImage id="yyy2" value="./javax.faces.resource/img/icon_alert.gif.jsf?ln=weblets.demo"/>

This is a set of different methods to generate valid weblet-JSF requests, which means all of those resources will be served by the JSF resource system.

The generated requests look like following:

<img id="yyy4" src="/weblets-demo/javax.faces.resource/1.0/img/icon_alert.gif.jsf?ln=weblets.demo" />
<img id="yyy5" src="./javax.faces.resource/1.0/img/icon_alert.gif.jsf?ln=weblets.demo" />
<img id="yyy2" src="./javax.faces.resource/img/icon_alert.gif.jsf?ln=weblets.demo" />

As you can see the generated requests are all valid JSF2 resource requests.

Now how about Subbundles?

Subbundles also work with the JSF2 API, following example demonstrates how you can work with subbundles.

<h:outputScript id="loadingBundleScript" library="weblets.demo" name="subbundle/script1.js"  target="body"/>
<h:outputScript id="loadingBundleScript2" library="weblets.demo" name="subbundle/script2.js"
                    rendered="#{wbl:isResourceLoaded('weblets.demo','/subbundle/script2.js')}"  target="body"/>

This is the exactly same example as before utilizing the JSF2 infrastructure of Weblets 1.3.

Links

[1] Weblets Homepage

[2] Weblets Documentation

Keine Kommentare:

Kommentar veröffentlichen