MojarraTeam

Mojarra 2.0.0 is now available!

There are several ways to obtain the release. 

Please review the release notes as there are important details there pertaining to differences between the implementation and the specification as well as a basic migration guide from 1.2 to 2.0 (note that this is a live document, so we'll be making additions - check back regularly).

The JSF 2.0 tutorial from our Sun documentation team should be available in the coming weeks.  As soon as it is, we'll send out a notification.  Until then, here are some nice resources for JSF 2.0:

On the tools+JSF 2.0 front, NetBeans is well underway with the JSF 2.0 support.  I'd recommend grabbing the NetBeans development build and try it out!  Ed noted the other day that you could highlight a section of markup in a Facelet template and extract it into a composite component.  Slick!  The JetBrains guys have been busy as well.  Check out their blog on JSF 2.0 support within Maia.

I'd like to personally thank all of our external contributors who have been committing code to the repository directly or submitting patches to help improve our quality (these are in no particular order - my apologies if I've missed anyone):

  • Guy Veraghtert
  • Imre Oßwald
  • Ted Goddard
  • Mark Collette
  • Dan Allen
  • Alexandr Smirnov
  • Martin Marinschek
  • Michael Kurz
  • Andy Schwartz

I'd also like to thank our top three issue reporters for taking the time to log issues (again, in no particular order)

  • Frank Hofmann
  • Guy Veraghtert
  • Juergen Zimmerman

Also, thanks to Ed Burns, Roger Kitain, Jim Driscoll, and Doug Donahue for putting up with me for the past two years while we worked on this project :)

Finally, if you'd like to discuss JSF 2.0 with other users, I'd recommend the following:

The GlassFish Webtier forums are monitored by the Mojarra developers.   The IRC channel, also, is frequented by the Mojarra developers, as well as folks from Exadel, MyFaces, and consumers of JSF as a technology.  It's a great way to interact with the community.

I'm excited that we've reached this stage and am looking forward to hearing/reading about people's experiences with JSF 2.0!

Using the f:ajax tag can make doing ajax with a repeating tag like ui:repeat considerably easier.
Dealing with field focus in JSF 2 and ajax. It's not hard, but you do have to keep a basic rule in mind: Don't update the parent of the field with focus.
In my last blog entry, I went over getting a YUI widget working on JSF2. This time, let's go over what's required to move that widget into a JSF component. No Java required, but a fair bit of JavaScript.
There's more to web development with JSF than just using JSF component libraries - there's a lot of really great widget sets out there that have nothing to do with JSF - here's a quick example of using one (the YUI Calendar widget) with JSF, Ajax, and a Managed bean.
About a year ago, I gave a talk at JavaOne on how to write a Comet powered TicTacToe game. At the time, I used the Grizzly Comet APIs. Here's an update for it to use the multi-platform Atmosphere API set.
Andy Schwartz, one of the JSF EG members, has written an excellent blog [1] on what's new in JSF 2.0.
Definitely worth a read!

[1] http://andyschwartz.wordpress.com/2009/07/31/whats-new-in-jsf-2/

David Geary has the third of his three part series of JSF 2 articles up. If you're getting started with JSF 2, go check it out - lots of good information there.
Hazem Saleh has posted a short blog on executing scripts in a JSF client page. Here's a link, along with some comments on his post.
How to satisfy compile time dependencies on JSR-303.
We've had another release of JSF 2, this one called Beta 2. The march toward FCS continues.
Recording of May JSF2 Complete Tour Webinar Available
Summary of a JavaOne hallway conversation about JSF: it's gotten a lot better.
Just a quick note to let folks know that 1.2_13 has been released.   Please see the announcement for details.

In this blog, I'll examine two different ways to create a poll component with JSF 2, and in doing so, we'll look briefly at the two different ways that you specify id's in the two JSF 2 Ajax APIs.
Just a quick note that we've now added automatic compression of the jsf.js file served by JSF 2. The file size of jsf.js, 71k uncompressed, comes to about 16k compressed (there are a lot of comments in there). There is no user action required to make this happen: If the Project stage is Development, the file is served uncompressed (for ease in debugging with something like Firebug), but if the Project stage is anything else, then the file is compressed (and essentially unreadable, since besides stripping all comments, variable names are stripped, as well as all line breaks).
It's come up a few times recently, so I thought I'd go over how to learn JSF 2 before the books come out, and before the new tutorial is released.
New JCP.org debuts, JSF2 DataSheet Published, Try the JavaEE 6 SDK
I describe how to get the latest JSF spec and implementation and how to provide feedback on it.
Ed's in-progress schedule for Jazoon 2009
Ben Galbraith did a short experiment on UI Latency at JavaOne. The results were not precisely what I expected.
I've uploaded my slides from my BOF last night, on creating components in JSF 2.
David Geary has released the second of his three part series on JSF 2.
JavaOne parties aren't what they used to be (ah, Borland, those were good times), but there's still quite a few to go around. Here's a list: ...
A common issue in JSF 1.1/1.2 was the inability to control the order in which faces-config.xml files were parsed when said files were included in a JAR file.  Why does ordering matter?  Consider the decoration of entities such as ViewHandler or Application.  If your application contains more than two ViewHandlers, you may wish to have the ViewHandler delegation chain configured in a certain order.
The same holds true for PhaseListeners.  A developer may wish to have PhaseListenerB execute before PhaseListenerA.

A stop-gap measure was implemented by Mojarra (MyFaces does the same I believe) where the ordering of META-INF/faces-config.xml documents was determined by the natural sort order of the JAR name that contained the file.  While this worked, it wasn't a perfect solution as you were then forced to rename the JAR files to achieve the desired result.

JSF 2.0 solves this by requiring implementations to support partial ordering of the configuration resources via the ordering element.
The ordering element offers a way for a single document to state it wishes to be ordered before or after a specific document, or a group
of documents.  Documents can be identified by the top-level name element.  It's imporant to note that there are two documents in configuration processing that are always processed in a specific order and as such the ordering element has no impact.  The implementation default configuration resource is always processed first and the WEB-INF/faces-config.xml (if present) is always processed last.

Given the above, let's start with an example straigh from the specification:

A.faces-config.xml:
<faces-config>
    <name>A</name>
    <ordering>
        <after>
            <name>B</name>
        </after>
    </ordering>
    <application>
        <view-handler>com.a.ViewHandlerImpl</view-handler>
    </application>
    <lifecycle>
        <phase-listener>com.a.PhaseListenerImpl</phase-listener>
    </lifecycle>
</faces-config>

B.faces-config.xml:
<faces-config>
    <name>B</name>
    <application>
        <view-handler>com.b.ViewHandlerImpl</view-handler>
    </application>
    <lifecycle>
        <phase-listener>com.b.PhaseListenerImpl</phase-listener>
    </lifecycle>
</faces-config>

C.faces-config.xml:
<faces-config>
    <name>C</name>
    <ordering>
        <before>
            <others />
        </before>
    </ordering>
    <application>
        <view-handler>com.c.ViewHandlerImpl</view-handler>
    </application>
    <lifecycle>
        <phase-listener>com.c.PhaseListenerImpl</phase-listener>
    </lifecycle>
</faces-config>
D.faces-config.xml:
<faces-config>
    <name>D</name>
    <application>
        <view-handler>com.my.ViewHandlerImpl</view-handler>
    </application>
    <lifecycle>
        <phase-listener>com.my.PhaseListenerImpl</phase-listener>
    </lifecycle>
</faces-config>


Looking over the four documents, we see that:
  • Document A is after document B
  • Document B has no ordering requirements
  • Document C is uses the others element to say it should be ordered
    before all the other documents that are being sorted
  • Document D has no ordering requirements
The resulting parse order may be:
  1. Implementation specific configuration resource
  2. Document C
  3. Document B
  4. Document A
  5. WEB-INF/faces-config.xml (if present)

Here's a couple other examples to illustrate an important point about the ordering.  When documents state they wish to be before or after another document, it may not necessarily be the case that the documents are ordered right next to each other.  I think the following examples will clarify what I mean:

Document A - <after><others/><name>C</name></after>
Document B - <before><others/></before>
Document C - <after><others/></after>
Document D - no ordering
Document E - no ordering
Document F - <before><others/><name>B</name></before>

The resulting parser order could be [F, B, D, E, C, A], but [F, B, E, D, C, A] would also be accurate.

Here's another:

Document <no id> - <after><others/></after><before><name>C</name></before>
Document B - <before><others/></before>
Document C - no ordering
Document D - <after><others/></after>
Document E - <before><others/></before>
Document F - no ordering

Possible parsing orders are:
  • B,E,F,<no id>,C,D
  • E,B,F,<no id>,C,D
  • B,E,F,C,<no id>,D
  • E,B,F,C,<no id>,D
An important note on that last example - if a document has ordering requirements, but no name, then the ordering requirements will be ignored.

Now, there are most likely going to be cases where the resulting partial parsing order doesn't quite fit with what an application needs.
In that case, the developer can fallback to another new element called absolute-ordering.  This element is only valid within the WEB-INF/faces-config.xml and will be ignored in all other cases.  The use of this element allows the developer complete control over the order that faces-config documents will be processed.

Here's a simple example:
<faces-config>
    <absolute-ordering>
        <name>C</name>
        <name>A</name>
    </absolute-ordering>
    .
    .
    .
</faces-config>

In this case, the parsing order would be:
  • Implementation specific configuration resource
  • Document C
  • Document A
  • WEB-INF/faces-config.xml
It's pretty simple, however, developers should be aware that any documents that aren't explicitly referenced within the absolute-ordering element will not be processed.  Though it is possible to include those documents without having to enumerate them all individually.

Consider:
<faces-config>
    <absolute-ordering>
        <name>C</name>
        <others />
        <name>A</name>
    </absolute-ordering>
    .
    .
    .
</faces-config>
In this example, assuming we started with documents [A, B, C, D], then the resulting parse order may look like:

  • Implementation specific configuration resource
  • Document C
  • Document B
  • Document D
  • Document A
  • WEB-INF/faces-config.xml

Note that B/D could be interchanged.  The others element may appear any where within the absolute-ordering element, but it may only do so once.

Per:  http://jcp.org/en/jsr/results?id=4939
The Unified Expression Language in EE6 is getting updated to support arbitrary/parameterized method calls without having to use static EL functions.

Here's is a quick example.  Consider the following managed bean:
public class TestBean {
    private List<String> names = new ArrayList<String>();

    public String greetName(String name) {
        names.add(name);
        return "Hello, " + name;
    }

    public List<String> getNamesGreeted() {
       return names;
    }
}

and now consider the following fragment from a Facelet view:
<h:outputText value="#{bean.greetName('Bill')}" /><br />
<h:outputText value="#{bean.namesGreeted.size()}" />

The first outputText will display "Hello, Bill", and the second, displays the size of the collection of all the names greeted, which in this simple example, would be "1".

So what about parameterized MethodExpressions (i.e. <h:commandButton action="#{bean.doAction(arg1, arg2)}" ... />)?
Well, this is currently a work in progress by the EL implementation folks.  Stay tuned for updates on this particular topic.

The new EL is already available in GlassFish V3, so if you're using V3 promoted builds, you can start taking advantage of the EL now with JSF and no configuration is necessary.

If you'd like to use the new EL in GlassFish V2, you can, as long as you're not using JSP.  The JSP compiler performs static analysis of the page being compiled and will complain when it encounters parameterized expressions.  This means you'll need to use an alternative view technology such as Facelets.

The EL libraries are available at the following URLs:
Copy the two JAR files to ${GLASSFISH_HOME}/lib, then edit ${GLASSFISH_HOME}/domains/<domain_name>/config/domain.xml and add the following attribute to the java-config element:
classpath-prefix="${com.sun.aas.installRoot}/lib/el-api-2.1.2-SNAPSHOT.jar:${com.sun.aas.installRoot}/lib/el-impl-2.1.2-SNAPSHOT.jar"
If the classpath-prefix attribute has already been defined, then append these two jars after the existing entries.  This modification will require a restart of the domain.  After these steps are complete, you should be able to leverage the new EL features.

Lastly, I'd recommend reviewing the change log for the new expression langauge to get familiar with what it offers and its limitations.
The JSF 2.0 specification is now in the final voting stage. This version of the specification defines how JSF frameworks integrate with Ajax. The Ajax integration portion of the specification was the result of a consolidated effort from an expert group that also included leaders from the major JSF Ajax frameworks such as ADF Faces/Trinidad (Oracle), ICEFaces (ICESoft), RichFaces (JBoss/Red Hat). ICESoft has already introduced ICEFaces 1.8 that runs on JSF 2.0, although it doesn't take advantage of any of the new features of JSF 2.0. I am happy to report that ICEFaces 2.0 is in the works and it leverages the extensibility points defined in the Ajax integration portion of the JSF 2.0 specification.
Some events for my JavaOne 2009 plan
This seems to be one of the top features users have been requesting for JSF 2.0.  For those of you not reading the specification revisions as it has been published, the feature is available.

Bookmarkability is achieved using two new components:
  • h:link
  • h:button
Both of these components will generate a URL based on the specified navigation outcome.  Keep in mind, that in JSF 2.0, implicit navigation is available, so this outcome can be defined within the view or using standard navigation rules.

So, let's start with a simple example using one of these new components with implicit navigation.  Please note that the following examples assume that the FacesServlet is mapped to '*.xhtml'.
    <h:link outcome="viewEntry" value="Link">
        <f:param name="entryName" value="#{someBean.entry}"/>
    </h:link>
In the example above, outcome, again, is the result of the navigation.  In this case, since we're assuming no navigation rules have been defined in the faces-config.xml, we're navigating to viewEntry.xhtml.  The f:param tag is adding a query parameter to the generated link.  When the component is rendered, the end result is something like:
<a href="http://localhost:8080/myapp/viewEntry.xhtml?entryName=entry1">Link</a>
The same can be achieved using navigation rules defined in the faces-config.xml.  For example:
<navigation-rule>
    <from-view-id>/page1.xhtml</from-view-id>
        <navigation-case>
            <from-outcome>redirectOutcome</from-outcome>
            <to-view-id>/page2.xhtml</to-view-id>
            <redirect>
                <view-param>
                    <name>entryName</name>
                    <value>#{someBean.value}</value>
                </view-param>
        </redirect>
    </navigation-case>
</navigation-rule>

Then reference the navigation outcome in one of the new components:
<h:link outcome="redirectOutcome" value="Link" />
which generates:
<a href="http://localhost:8080/myapp/page2.xhtml?entryName=entry1">Link</a>
Now, there's a third source of parameters that has been introduced in JSF 2.0 called 'View Parameters'.  These parameters are specified as metadata to the page and can be included in the generated URLs.  There's a lot more to view parameters than what is about to be shown.  I'll go more into that later on in this entry. 

Here's a simple example of a View Parameter (assume this is defined within somepage.xhtml):
<!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:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
<head><title>somepage</title></head>
<body>
        <f:metadata>
            <f:viewParam id="id" name="viewParam" value="#{someBean.id}" />       
         </f:metadata>
         .
         .
</body>
</html>

If the developer sets the 'includeViewParams' attribute on h:link or h:button or the include-view-params attribute on the redirect element of a navigation-case to true, then the UIViewParameters will be a part of the generated URL.

So, building off of the metadata example above, consider the following h:link within another view:
<h:link outcome="sompage.xhtml" value="Link">
    <f:param name="componentParam" value="component"/>
</h:link>
The generated URL would look like:
<a href="http://localhost:8080/myapp/somepage.xhtml?componentParam=component&viewParam=view">Link</a>
Keep in mind that the view parameters that are included in the generated URL will be those of of the view being navigated to.

It's also important to note that there is an order of precedence for adding the parameters from the different sources.  This order is essentially, component, navigation-case parameters, followed by view parameters.  This means that if a component specifies a parameter via f:param that has the same name as that in a navigation-case or in the view metadata, then the parameter value from the navigation-case or view metadata will not be included in the query string.  

Now, getting back to view parameters, there's some other details I'd like to share.  In 1.2, the typical GET lifecycle would result in the restore view phase being invoked immediately followed by render response.  This is still true in 2.0 *except* when the view being processed has view parameters.  In this case, the view parameters are processed using the standard post-back processing lifecycle (i.e. apply request values,  process validations, update model, invoke application, then render response).   Processing view parameters in this fashion allows developers to attach converters and validators to the view parameters to enforce the integrity of the parameter data being passed to the view.  For example:

         <f:metadata>
            <f:viewParam id="id" name="id" value="#{newsReader.selectedStoryId}"
                     required="true"
                     requiredMessage="You did not specify an id. (The id parameter is missing)"
                     converterMessage="Invalid id. (The id parameter is not a number)"
                     validatorMessage="Invalid id. (The id parameter is not a positive number)">
                <f:validateLongRange minimum="1"/>
            </f:viewParam>       
         </f:metadata>


Lastly, developers need not restrict their usage of f:metadata to view parameters only.  Facelets templating features and view events (i.e. f:event) can also be specified.  One useage restriction of f:metadata needs to be kept in mind though - it must be defined within the view and not within a template.  If this restriction isn't observed, the content within f:metadata will not be processed.

That should cover the basics for now.  Please download the Mojarra 2.0.0 nightly and give this feature a shot.  Feel free to ask questions on the GlassFish Webtier forums, and if you think you found an issue, please let us know about it.