My JSF Books/Videos My JSF Tutorials OmniFaces/JSF PPTs
JSF 2.3 Tutorial
JSF Caching Tutorial
JSF Navigation Tutorial
JSF Scopes Tutorial
JSF Page Author Beginner's Guide
OmniFaces 2.3 Tutorial Examples
OmniFaces 2.2 Tutorial Examples
JSF Events Tutorial
OmniFaces Callbacks Usages
JSF State Tutorial
JSF and Design Patterns
JSF 2.3 New Features (2.3-m04)
Introduction to OmniFaces
25+ Reasons to use OmniFaces in JSF
OmniFaces Validators
OmniFaces Converters
JSF Design Patterns
Mastering OmniFaces
Reusable and less-verbose JSF code

My JSF Resources ...

Java EE Guardian
Member of JCG Program
Member MVB DZone
Blog curated on ZEEF
OmniFaces is an utility library for JSF, including PrimeFaces, RichFaces, ICEfaces ...

[OmniFaces Utilities] - Find the right JSF OmniFaces 2 utilities methods/functions

Search on blog

Petition by Java EE Guardians


joi, 10 decembrie 2015

JSF 2.3 Default Producer Example

As you probably know, JSF uses static entry methods and chaining to let the user obtain the various artifacts that it provides, such as the FacesContext, session map, external context, etc. But, this is pretty verbose and sometimes hard to intuit and understand. JSF 2.3 will therefore provide default producers for the most important artifacts. The entire list in available here.

In this post, you can see a simple example of injecting the request parameters map. So, let's have a simple Facelets:

  <h:commandButton value="Hello World!" action="#{helloWorldBean.sayHello()}">                                   
   <f:param name="year" value="2016"/>

Now, in the HelloWorldBean we inject the request parameters map and access the year request parameter:

import java.util.Map;
import javax.enterprise.context.RequestScoped;
import javax.faces.annotation.RequestParameterMap;
import javax.inject.Inject;
import javax.inject.Named;

public class HelloWorldBean {

 private Map<String, String> requestMap;

 public void sayHello() {
  System.out.println("Hello World in " + requestMap.get("year"));

Output in console will be:
Hello World in 2016

Note In order to activate the CDI EL resolving and injection (for now) the context parameter javax.faces.ENABLE_CDI_RESOLVER_CHAIN needs to be set to true (otherwise EL resolving will use the old (JSF native) implicit object resolver, and injection will not work (throws exception)):


The complete application is available here.

Special thanks to Arjan Tijms for contributing to this post.

2 comentarii :


Postări populare

Follow by Email

Visitors Starting 4 September 2015

Locations of Site Visitors