Usage of Weblets in a jsf centric environment
As
The generic tooling support of course also works in JSF, but it doesn�t have to be used, due to the easier
configuration and usage of the internal
Setup
Details of the setup are described in the Setup guide .
Setup Short summary:
Every basic
Code 0: valid path pattern in the web.xml
<servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>/faces/*</url-pattern> </servlet-mapping>
Of course file patterns can be used additionally.
Another limitation of this system is, if you use a
Basic Functions
Introduction
The Weblets APIs follow the general patterns as described in Weblets Users Guide: Introduction to the API Patterns . for further information please follow the link.
JSF Frontend APIs
Over the years
JSF 1.1
Although nowadays basically a legacy technology, but still widely used,
Now to use
- For cases outside of the
JSF area (areas in your page outside of f:view) rely on basic jsp mechanisms as described in JSP : Usage page - Within
JSF areas you can rely on anEL dummy map provided automatically to yourJSF system. To use it no additional configuration is needed
The following code example showcases the usage of this
Code 3: Usage or resource and url in a JSF frontend environment
<h:outputText value="#{weblet.url['weblets.demo']['/welcome.js']}" /> <h:graphicImage value="#{weblet.resource['weblets.demo']['/img/icon_alert.gif']}" />
In this example you can precisely see why you need sometimes resource
Code 4: Difference between url and resource in a JSF specific api
#{weblet.url['weblets.demo']['/welcome.js']}
Is a typical
Facelets and
JSF
1.2
The last years facelets has become the frontend technology for many projects. One of the advantages
of facelets is that it already provides a JSP 2.x and
If you are in a facelet domain you have two options to utilize weblets
- via
EL functions (the same as in jsp 2.x) - via the above described dummy maps
Newer
The next example shows how to use the
Code 5: Usage of EL functions in faclets
xmlns:wbl="http://weblets.dev.java.net/facelet-tags" this has to be added to your namespace definitions <h:outputText value="${weblet:url('weblets.demo','/welcome.js')}" /> <h:graphicImage value="${weblet:resource('weblets.demo','/img/icon_alert.gif')}" />
xmlns:wbl="http://weblets.dev.java.net/tags" <h:outputText value="${weblet:url('weblets.demo','/welcome.js')}" /> <h:graphicImage value="${weblet:resource('weblets.demo','/img/icon_alert.gif')}" />
As you can see the calls are very similar, but instead of reverting into a (still available)
For an extensive examples of the EL function calls, check out the weblets-demo application provided with your weblets download package
JSF 2.x Resource Handlers
If you have reached this section in the documentation you are probably aware that JSF has introduced its own Resource mechanism. The so called ResourceHandlers and Resources. So how do you combine this with Weblets. Weblets 1.3+ provides its own ResourceHandler and Resource class which allows to access your Weblets hosted resources from within the JSF Resource API. The usage is very simple, any JSF Resource request which hits a valid Weblet resource will be served as is. So following code:<h:graphicImage id="yyy2" value="./javax.faces.resource/img/icon_alert.gif.jsf?ln=weblets.demo"/>
<h:graphicImage id="standardRequest" value="./javax.faces.resource/img/icon_alert.gif.jsf?ln=weblets.demo"/> <h:graphicImage id="helperMap" value="#{weblet.jsfURL['weblets.demo']['/img/icon_alert.gif']}"/> <h:graphicImage id="elFunction" value="#{wbl:jsfURL('weblets.demo','/img/icon_alert.gif')}"/> <h:graphicImage id="elFunctionWithResource" value="./#{wbl:jsfResource('weblets.demo','/img/icon_alert.gif')}"/>
<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"/>
Backend APIs for the Component and Bean Developers
Component and backend authors in
- a document root and relative resources
- a view handler
handler.getResourceURL(context, "/myresources/myScript.js"); In both methods you have to pack the resources into your application, you have to take care about their precise location in your document tree etc... This is burden and error prone, and resources can be traced down to their actual location which opens another door for hackers to bring in trojan horses! Besides that, changing the location or even physical source of any resource might cause changes in the entire application tree and even some components!
Now
Weblets is here to solve all those problems. And again we revert to our proven url and uri notation.Weblets provides for many backend technologies Utils classes which provide the usual url and uri notations,JSF as well:Code 6: Usage contractual API the <<<JSF >> way>
FacesWebletUtils.getURL(context, "demo.webletname", "/subpath/myresource.js") FacesWebletUtils.getResource(context, "demo.webletname", "/subpath/myresource.js") Context being the Faces Context!
That is basically it, nothing more and nothing less. It is easy to call
Weblets from your backing bean or component, all you have to do is, to use the provided API calls! And then work with their return values as you would with other url strings!
Summary
The usage of
- Basic JSP mechanisms
-
JSF dummy maps -
EL functions for newerEL implementations
Also for the component and bean developers easy to use
Contents
- Users documentation: Index
- What is new in this release
- Users documentation: Getting started
- Users documentation: Setup guide
- Users documentation: Introduction to the api patterns
- Users documentation: JSP Weblets usage guide
- Users documentation: Servlet Weblets usage guide
- Users documentation: JSF Weblets usage guide
- Users documentation: Resources Weblets usage guide
- Users documentation: Weblets packaging guide
- Users documentation: Weblets Subbundles
- Users documentation: Weblets reporting guide
- Developers documentation: Programming Weblets
- Users documentation: Weblets general FAQ