jsr372-experts@javaserverfaces-spec-public.java.net

[jsr372-experts] Re: Annotation to enable/configure JSF?

From: manfred riem <manfred.riem_at_oracle.com>
Date: Tue, 15 Dec 2015 11:03:45 -0600

Hi Arjan,

Interesting idea.

Thanks!

Kind regards,
Manfred Riem

On 12/15/15, 7:41 AM, arjan tijms wrote:
> Hi,
>
> One of two ways to automatically enable JSF in a project is having
> either a class on the class path annotated with one of the JSF native
> annotations, or having a /WEB-INF/faces-config.xml file present.
>
> With the world moving to CDI, the JSF native annotations (specifically
> @MangedBean) are not so much used anymore. This way to enable JSF is
> not so practical anymore.
>
> A faces-config.xml file is still a simple way, if it wasn't for the
> fact that officially (if I'm not mistaken) it can't be just an empty
> file like CDI's bean.xml. Looking up the right schema for trivial
> applications is a bit of a hassle.
>
> I was thinking that instead of using existing JSF annotations that as
> a side-effect enable JSF, it might be worth looking into a JSF
> annotation that is specifically intended to enable JSF.
>
> E.g.
>
> @ActivateJSF
> public class JustAClass {
>
> }
>
> The name "ActivateJSF" is just an example and could be any other name.
> Some other candidates @JSF, @JSFConfig, @JSFActivation,
> @ActivateFaces, @FacesConfig, @FacesParams, etc
>
> In the simplest version this will just activate JSF like @ManagedBean
> does, but without the side effect of also creating a (potentially
> unused) managed bean.
>
> One step further may be to add some configuration options, potentially
> the annotation variant of the various web.xml settings.
>
> E.g.
>
> @ActivateJSF(
> stateSavingMethod = "server"
> )
>
> Or a new option, to indicate the JSF version:
>
> @ActivateJSF(
> version = "2.3" // enables all JSF 2.3 features
> )
>
> @ActivateJSF(
> version = "2.2" // behaves as much as possible as 2.2 did
> )
>
> Yet another step further, if the class on which @ActivateJSF appears
> is a CDI bean, alternatives can be used to switch configuration.
>
> I experimented with this locally in the Mojarra source code, and in
> some experiments it worked quite nicely.
>
> Thoughts?
>
> Kind regards,
> Arjan Tijms
>
>