Showing posts with label JSF. Show all posts
Showing posts with label JSF. Show all posts

Sunday, 29 July 2012

JSF: CDI and EL

The Contexts and Dependency Injection (CDI) API introduced in Java EE 6 complements the JSF framework. There are good reasons to favour it over JavaServer Faces (JSF) managed bean mechanisms.

CDI doesn't do everything and there are edge cases where you might want to make use of Expression Language (EL) bindings during dependency injection. Fortunately, the gaps between these APIs are easy to fill.

Monday, 2 January 2012

JSF: managed beans without JSF dependencies

A previous post discussed how to inject the FacesContext into managed beans using a broker. This post demonstrates how to build on that approach with greater levels of abstraction.

It is generally possible to remove direct JSF dependencies from managed bean code. You might want to do this to reduce coupling, improve cohesion or in the interests of writing testable code.

The code was written against Java 6, JSF 2 and JUnit 4 but the approach could be adapted to earlier versions of all of these.

Tuesday, 27 December 2011

JSF: mocking FacesContext for unit tests

Referencing the FacesContext directly in Java classes makes managed beans more difficult to unit test. This post discusses how to mock the context for testing outside the application container.

These examples use Mockito with JUnit. Familiarity with JSF and unit testing Java is assumed.

I've used the javax.faces.bean annotations but the techniques apply for other bean management mechanisms (e.g. using faces-config.xml or Spring).

Sunday, 27 November 2011

JSP: arbitrary attributes on JSF controls

One criticism developers have of JavaServer Faces is that it is not possible to add arbitrary attributes to the resultant markup. Problems arise when they wish to add custom attributes specific to JavaScript frameworks (e.g. dojoType for the Dojo toolkit) or HTML 5 attributes (such as data- or placeholder.)

However, this is not a technical limitation of the JSF framework; only a limitation of the standard control library.

Friday, 9 October 2009

JSF: working with component identifiers (id/clientId)

This is a post about how to work with IDs in JavaServer Faces. You may find this useful if you want to use JavaScript with JSF.

Example ID developer sets on a JSF component:  foo1
What JSF might render in the resultant HTML:   j_id_jsp_115874224_691:table1:0:foo1

This is a revised version of JSF: working with component IDs (id vs clientId), though you don't need to read that. This post fixes some of the issues with the code, provides a more robust version of the library and details how to use it to make simpler, more reliable applications. The target JSF version is 1.2.

Saturday, 1 August 2009

JSF: a custom format panel control for localising component layout

This post describes a custom JavaServer Faces component for controlling the flow layout of controls based on localised strings.

Wednesday, 27 May 2009

JSF: using component IDs in a data table (h:dataTable vs clientId)

Updated 2009/11/24

This post is obsolete; go read this one instead: JSF: working with component identifiers The approach described in this post may fail if the component identifiers are not unique within the view.

Tuesday, 19 May 2009

JSF: IDs and clientIds in Facelets

Updated 2009/11/24

This post is obsolete; go read this one instead: JSF: working with component identifiers The approach described in this post may fail if the component identifiers are not unique within the view.

Monday, 16 February 2009

JSF: working with component IDs (id vs clientId)

Updated 2009/10/17

WARNING: this post is obsolete; go read this one instead.