23 Apr

Apache MyFaces Core 2.0.0 released

After the final release of the JSF 2.0 specification (JSR-314) in July 2009, the first alpha release in November 2009 and some beta releases in February and March 2010, Apache MyFaces Core 2.0.0 was released today. The release is 100% complaint with the JSR-314 specification and has passed Sun’s JSR-314 TCK.

You can download MyFaces Core 2.0.0 here or you can find it in the central Maven repository under Group ID “org.apache.myfaces.core”.

So now there is no reason anymore not to try it out yourself. You can check out all new features of JSF 2.0 with MyFaces Core 2.0.0 like e.g. composite components, the integrated Facelets view declaration language or the very easy AJAX support via f:ajax, just to mention a few here.

And please do not hesitate to file any issues you might run into in our bug tracker or to ask any questions you might have on our mailing list(s). We are very happy with every feedback we get!

You can also check out the related article on heise Developer (in German): JSF-Implementierung Apache MyFaces 2.0 erschienen

10 Apr

JSF 2.0: View parameters

One very cool new feature of JSF 2.0 are view parameters. If you are now wondering what I mean with a view parameter (or request parameter) – here’s the answer: Do you know those things at the end of an URL that often look like ?id=3&page=2, then you know what I mean. If not, take a look at this. The great advantage of these view parameters is that JSF’s URLs are now bookmarkable, because all values that are needed to display a certain page can be provided via the URL.

JSF 2.0 introduces a new UIInput component especially for view parameters called UIViewParameter. This component extends UIInput and thus has the same functionality as e.g. <h:inputText />. This means it can have converters and validators, its value is bound to a model (managed bean) and it goes through the JSF-lifecycle just as every other EditableValueHolder.

To define an UIViewParameter in your view you just have to add a <f:viewParam /> element inside your view metadata facet. Sounds complicated, but actually it is not, as you can see in the following Facelet page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
 xmlns:h="http://java.sun.com/jsf/html"
 xmlns:f="http://java.sun.com/jsf/core"
 xmlns:ui="http://java.sun.com/jsf/facelets">

<f:metadata>
    <f:viewParam name="input" value="#{myBean.input}" />
</f:metadata>

<h:head>
    <title>UIViewParameter example by jakobk</title>
</h:head>
<h:body>
    The view parameter's value is:
    <h:outputText value="#{myBean.input}" />
</h:body>
</html>

If you now access this page with http://localhost:8080/pathToWebapp/view.xhtml?input=abc, #{myBean.input} will be set to “abc”.

Very important for this feature to work is to use the JSF 2.0 built-in Facelets-2 view declaration language and not JSP or Facelets-1.x. Although the <f:viewParam /> tag is defined for JSP in the specification javadoc, the <f:metadata /> tag is missing and also I could not make it work. However I will dig into this and write another blog post about the JSP support soon. If you are currently using Facelets-1.x with JSF 2.0, just get rid of <view-handler>com.sun.facelets.FaceletViewHandler</view-handler> in your faces-config to upgrade to the JSF 2.0 built-in Facelets-2.

If you want your view parameter(s) to be required to render the view (which will be most likely, I guess), you just have to add required=”true” to <f:viewParam /> and your view will not accept any inputs or actions unless the view parameter is provided. In addition and as mentioned before, you can attach any kind of converters or validators (with the help of any <f:converter /> and/or <f:validator /> tags) to your <f:viewParam /> to verify the value. The following snippet shows a view parameter which only accepts non null Strings that are at least 3 characters long:

<f:viewParam required="true" name="input" value="#{myBean.input}">
    <f:validateLength minimum="3" />
</f:viewParam>

The UIViewParameter component also stores its value in the state, so that the value will also be available on the next postback request (most likely a clicked button or link). So you only need to provide your view parameter(s) once and not on every request.

On my opinion, view parameters are a really cool new feature of JSF. Of course, you were able to do the same thing with JSF 1.x and the request parameter map from ExternalContext, but this just was not very elegant and in case of conversion and validation also far more complicated.

More detailed information about view parameters can be found on the specification javadoc of <f:viewParam />.

08 Apr

System.out.println(“Hello world!”);

Sometimes I think to myself: “this would be a good subject to write a blog entry about”, but I just never did it. Now the time has come and I created my own blog.

This blog will mostly be about Apache MyFaces and thus about JSF and Java related topics.

I hope you will enjoy it!