JSF 2.0: A Component's Controller

After my last blog post on composite components, Ed Burns, the spec lead, pointed out a better way to do things, by using a controller for the component. Here's a short explanation of what to do to make that work.

After my last blog post[2] on composite components, Ed Burns, the spec lead, pointed out a better way to do things, by using a controller for the component. Let's go over a simple example of how that would work. The example won't actually do anything (unlike most of my examples, which at least pretend to perform a function) - I just want to sketch out a single, simple concept, and show it in code.

We'll create a component that takes a single argument - but that argument will actually consist of two different values, bundled into a single bean. Here's the meat of the bean's code:

I'm pretty sure that this doesn't need much explanation, but just in case - I've declared that the component takes one attribute - controller, and that that controller has two fields, number1 and number2. Then, in the implementation section, I can reference those fields with a simple dot notation.

As always, this code is available in Mojarra[3]'s jsf-demo directory, in this case, under the basic-ezcomp directory.