Tuesday, April 6, 2010

Bit #5 - Accessing a resource bundle from a backing bean

You can access a resource bundle from a backing by calling the getResourceBundle() method on a javax.faces.application.Application object and specifying the bundle name. You get the Application object by calling getApplication() on the FacesContext. The getResourceBundle() returns a ResourceBundle object. To get some resource data from the bundle, call getString() on the ResourceBundle specifying the resource identifier. The example below illustrates the case.

Example:


        FacesContext fc = FacesContext.getCurrentInstance();
        ResourceBundle bundle = fc.getApplication().getResourceBundle(fc,"bundle_name");
        bundle.getString("resource_identifier");


Context:

Resource Bundle
Backing Bean


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...