Covers new features in JSF 2, community involvement in JSF and a look towards the future of this framework.
Presented by Dan Allen, Pete Muir and Andy Schwartz at Devoxx 2009.
http://www.devoxx.com/display/DV09/JSF+2+and+beyond
8. 16-11-09 Many faces of JSF 2 Andy Schwartz Dan Allen Jacob Hookom Alexandr Smirnov Ken Paulsen Martin Marinschek Matthias Wess endorf Pete Muir Alexander Jesse Imre O ßwald Yara Senger Lincoln Baxter Adam Winer Craig McClanahan Kito Mann Rick Hightower Joe Ottinger Ted Goddard Neil Griffin Jason Lee Stan Silvert David Geary Micheal Freedman Hazem Saleh Çağata Çivici Dennis Byrne Roger Keays Amy Fowler Max Katz Jeremy Grelle Keith Donald Emmanuel Bernard Ed Burns Jim Driscoll Roger Kitain Ryan Lubke Nick Belaevski Gavin King
85. Post-mapping event listener 16-11-09 <f:view> <f:metadata> ... <f:event type = " preRenderView " listener = "#{catalogBean.onRender}" /> </f:metadata> ... </f:view> Declarative system event No-args method or method that accepts ComponentSystemEvent
86. Hold the rendering! 16-11-09 public void onRender() { FacesContext ctx = FacesContext.getCurrentInstance(); if (ctx.isValidationFailed() || !loadDataAttempt()) { ctx.getApplication().getNavigationHandler() .handleNavigation(ctx, null , "invalid" ); } } Force navigation if preconditions not met
89. View actions 16-11-09 <f:view> <f:metadata> ... <f:viewAction execute="#{catalogBean.onRender}"/> </f:metadata> ... </f:view> Wouldn’t it be nice if we had...? JSF 2.next Including option to disable on postback
97. Generating bookmarkable links 16-11-09 <h:link value = "Previous" includeViewParams = "true" > <f:param name = "page" value = "#{catalogBean.previousPage}" /> </h:link> <f:metadata> <f:viewParam name = "q" value = "#{catalogBean.query}" /> <f:viewParam name = "page" value = "#{catalogBean.page}" /> </f:metadata> http://acme.org/catalog.jsf? q=portable+hole & page=3 /catalog.xhtml
98.
99. 16-11-09 Navigation Implicit, conditional and preemptive navigation, queryable navigation rules and redirect parameters
100.
101.
102. A navigation shorthand 16-11-09 <h:commandButton action = "#{productBean.save}" value = "Save" /> public String save() { // perform save logic, then... return "/catalog.xhtml" ; }
103. A navigation short (er) hand 16-11-09 Can link to navigation case later <h:commandButton action = "#{productBean.save}" value = "Save" /> public String save() { // perform save logic, then... return " catalog " ; } Relative to current path and view ID
104.
105.
106. A conditional case 16-11-09 <navigation-case> <from-action> #{registration.register} </from-action> <if>#{currentUser.registered}</if> <to-view-id> /account.xhtml </to-view-id> <redirect include-view-params = "true" /> </navigation-case>
124. 16-11-09 Model Java EE 6 component model, Bean Validation, error handling and resource loading
125.
126.
127.
128.
129.
130. Simple example 16-11-09 public class Hello { public String sayHello(String name) { return "Hello, " + name; } } @Stateless public class Hello { public String sayHello(String name) { return "Hello, " + name; } } Any Managed Bean can use CDI services ...even EJBs!
131. Simple example 16-11-09 public class Printer { @Inject Hello hello ; public void printHello() { System.out.println( hello .sayHello( "Devoxx" )); } } @Inject defines injection point, assumes @Default qualifier
132. Constructor injection 16-11-09 public class Printer { private Hello hello ; @Inject public Printer(Hello hello) { this . hello = hello; } public void printHello() { System. out .println( hello .sayHello( "Devoxx" )); } } @Inject marks constructor to be called by container; arguments injected automatically
133. Bean EL names 16-11-09 @Named( "hello" ) public class Hello { private String name; // getters and setters not shown public void sayHello() { System. out .println( "Hello, " + name); } } @Named public class Hello { ... } @Named makes bean available to EL Name can be defaulted to simple name of class
134. JSF view 16-11-09 <h:inputText value = "#{hello.name}" /> <h:commandButton value = "Say Hello" action = "#{hello.sayHello}" /> Invoking a bean via EL
135. 16-11-09 Qualifier An annotation that lets a client choose between multiple implementations of an API at runtime
136. Write a qualified implementation 16-11-09 @Casual public class Hi extends Hello { public String sayHello(String name) { return "Hi, " + name; } } This second Hello bean is qualified @Casual
137. Using a qualifier 16-11-09 public class Printer { @Inject @Casual Hello hello ; public void printHello() { System. out .println( hello .sayHello( "Devoxx" )); } } Injects the @Casual implementation of Hello
138.
139.
140.
141. 16-11-09 Validation Bean Validation integration, validating empty fields and multi-field validation with post-validate events
142. 16-11-09 One model... ...validated across multiple layers Constraints in the enterprise User String username String email
143.
144. Defining constraints on the model 16-11-09 public class User { ... @NotNull @Size(min = 3, max = 25) public String getUsername() { return username ; } @NotNull @Email public String getEmail() { return email ; } }
145. 16-11-09 One model... ...validated across multiple layers Constraints in JSF User String username String email
146. Enforcing constraints in the UI 16-11-09 <h:inputText id = "username" value = "#{user.username}" /> <h:inputText id = "email" value = "#{user.email}" /> Zeroconf!
147. Constraining partially 16-11-09 <h:inputText id = "username" value = "#{user.username}" > <f:validateBean disabled = "true" /> </h:inputText> <f:validateBean validationGroups = "com.acme.BareMinimum" > <h:inputText id = "email" value = "#{user.email}" /> </:validateBean>
148.
149.
150.
151. Listening for post validate 16-11-09 <h:form> <f:event type="postValidate" listener="#{minMax.validate}"/> <h:inputText id = "min" value = "#{bean.min}" binding = "#{minMax.minInput}" /> <h:inputText id = "max" value = "#{bean.max}" binding = "#{minMax.maxInput}" /> <h:commandButton value = "Submit" /> </h:form>
152. Validating across fields 16-11-09 @Inject FacesContext ctx ; private UIInput minInput , maxInput ; // accessors hidden public void validate () { if ( ctx .isValidationFailed()) { return ; } if ((Integer) maxInput .getValue() < (Integer) minInput .getValue()) { ctx.addMessage( maxInput .getClientId(ctx), new FacesMessage( "cannot be less than min value" )); ctx.validationFailed() ; ctx.renderResponse(); } }
153.
154. 16-11-09 Error handling Exception handlers, exception events, servlet errors and the default error page
161. Declarative error handling in JSF 16-11-09 <exception class = "javax.persistence.EntityNotFoundException" > <redirect view-id = "/error/404.xhtml" > <message severity = "warn" > Record not found </message> </redirect> </exception> Wouldn’t it be nice if we had...? JSF 2.next
162.
163. 16-11-09 Pain relief Select items from collections, validation failed flag, API improvements, varStatus on ui:repeat, and more...
164. From collection to select items 16-11-09 <h:selectOneMenu value = "#{product.category}" > <f:selectItems value = " #{catalogBean.categories} " var = "cat" itemLabel = "#{cat.name}" itemValue = "#{cat}" noSelectionValue = "#{catalogBean.defaultCatalog}" /> </h:selectOneMenu> @Named public class CatalogBean { public List<Category> getCategories() { return ...; } }
170. 16-11-09 Creating a JCP.org profile Did you know that anyone can have a JCP.org profile? Just sign up!
171.
172. 16-11-09 Becoming a JCP member Did you know that anyone can become a JCP member? Just sign the JSPA!
173.
174.
175.
176.
177.
Hinweis der Redaktion
We are going to have a great time this afternoon....because if the colors in that slide only get your fired up (or make your eyes bleed)....we'll, I don't know what's going to do it.In this talk we are going to be talking about progress. Specficially progress in JSF.Look, progress was a little bit of a stranger to JSF when the spec first opened. But it eventually found it's way and momentum has been steadily picking up right and plowed right through the final release of JSF 2. Now, there's been more active on the JSF development list since it became final than at any other point. We got a lot of what we wanted, but now we want more. (In fact, just creating this talk helped us identify areas for improvement). JSF 2 features were derived from community, precendent.
The goals of this talk are to pull off on the side of the road and look at where we've been, to explain the community's role in the making of JSF 2 and how you can help shape JSF 2.next and a glimpse at some of the things are in store for JSF 2.next. You may wonder what &quot;.next&quot; is all about. We'll, at this point we are really not sure whether the next version is JSF 2.1, 2.2 or some other version, or what JSR it's going to be under. But we are committed to seeing it happen, and with urgency. JSF 2.next also happens to be the issue tracker tag designated for future issues, so it's a bit of a play on that.
The underlying theme of this talk is collaboration and community involved. (conference theme) So before we get into the talk, we want to enourage you to feel like you are a part of it right from the beginning. Expecting you guys to speak out in a forum like this is often wishful thinking. Instead, you can interact in a way familiar to a lot of you, using twitter. I've selected the hashtag #jsf2next for you to make suggestions, ask questions or request clarification. At points during the talk, maybe not until the end, we'll parse this feedback and customize the content. That way, you'll really feel like your are involved. Even if we don't get to all the comments, it's a perfect starting point for tonight.
So speaking of birds and feathers, there is a BOF tonight at 20:00 that will be the ideal break-out session to comlement this talk. So comment in twitter now, and if we don't get to it, then it's a conversation piece for tonight.I'd like to take this opportunity to tell you who we are.
Primary reason I am standing here today is because of what I wrote in Seam in Action; recognized where JSF could be improved (James Cobb, who came through in the clutch to put together some colors for us to use in code snippets)You'll notice that this is a joint talk because Oracle and Red Hat. Although we work for different organization, we are collegues on the JSR-314 EG. We are also members of the broader JSF community which we represent.But it's not just about our two organizations. We stand up hear representing the JSF EG. We feel a very strong alliance in this spec, one that you can certainly be proud of as community members. A lot of people have been involved in JSF; i've done my best to identify the faces of JSF, past, present and future [Faces of JSF slide]
We're going to break this talk up into parts, each of which one of us will be covering. Subconsciously, the topic areas sort of just fell into MVC, which is the foundation pattern of JSF. Also nicely breaks down between two halfs of this talk. First half, point, second half point. We'll do a short break in between to let you stretch your legs and brains (and to get in a few tweets).
Let's get on with it, shall we. I'll now turn the floor over to Andy, who is going to show you how slick the view creation has become, complete with Ajax, JavaScript APIs and powerful templating.
Point is, no special tricks
PreRenderView event loop
Serve resource files natively out of a Java archive
* Emphsize the web profile - lightweight, aimed at developing “web” apps
* We can improve on the syntax for this! f.e. make faces messages easier to add, add some syntatic sugar i.e. consider this an idea, not the canonical way to do it
* Discuss JSF design flaw - exceptions for flow control!