users@javaserverfaces-spec-public.java.net

[jsr372-experts mirror] [jsr372-experts] Re: Tag to declare and import constants in EL scope

From: Leonardo Uribe <leonardo.uribe_at_irian.at>
Date: Tue, 21 Jun 2016 14:59:06 +0200

Hi

I see, so it is better if it is set as part of faces-config.

Really there is a precedent of a similar tag. In tomahawk there are
t:aliasBean and t:aliasBeansScope, which are tags designed to create
temporal names for bean that are only valid for child components.

This case is just similar, but for constants.

Other option I can imagine is make it in the same way f:viewParam in
f:metadata works.

<f:metadata>
    <f:importConstants type="com.example.Gender" />
</f:metadata>

Then f:importConstants add the definition (which is in fact metadata) to
UIViewRoot. Since everything inside f:metadata is read before the view is
actually populated, things will work fine (but note f:importConstants is
enforced to be added inside f:metadata, which has sense).

regards,

Leonardo Uribe


2016-06-20 20:33 GMT+02:00 Bauke Scholtz <balusc_at_gmail.com>:

> I don't think using an annotation is a good idea. Usually models reside in
> business/service (EJB) layer and you don't want to have JSF dependencies
> over there.
>
> Cheers, B
>
> On Mon, Jun 20, 2016 at 3:36 PM, arjan tijms <arjan.tijms_at_gmail.com>
> wrote:
>
>> On Mon, Jun 20, 2016 at 3:24 PM, Bauke Scholtz <balusc_at_gmail.com> wrote:
>>
>>> A faces-config.xml based configuration is a reasonable idea. Perhaps
>>> even better.
>>>
>>
>> And/or the upcoming @FacesConfig ;)
>>
>> Kind regards,
>> Arjan Tijms
>>
>>
>>
>>
>>>
>>> Cheers, B
>>>
>>>
>>> On Mon, Jun 20, 2016 at 3:14 PM, Leonardo Uribe <leonardo.uribe_at_irian.at
>>> > wrote:
>>>
>>>> Hi
>>>>
>>>> Just as a comment, f:importConstants reminds me f:loadBundle, which was
>>>> deprecated and replaced by a solution that loads the bundle from the
>>>> faces-config.xml files.
>>>>
>>>> The problem about f:importConstants is how to set up the context where
>>>> these constants are available. For example
>>>>
>>>> <f:importConstants type="com.example.Gender" />
>>>>
>>>> <h:selectOneMenu value="#{person.gender}">
>>>> <f:selectItems value="#{Gender}" />
>>>>
>>>> <f:ajax ...../>
>>>> </h:selectOneMenu>
>>>>
>>>>
>>>> if the ajax is only for the component, f:importConstants can be ignored
>>>> and the code will break.
>>>>
>>>> so, the "challenge" is to find a way to define the EL context properly.
>>>>
>>>> In MyFaces there are some EL contexts:
>>>>
>>>> - page
>>>> - template
>>>> - view
>>>> - global
>>>>
>>>> Sometimes you want a definition to pass through the template, sometimes
>>>> through the view or sometimes just have a global definition for all your
>>>> views.
>>>>
>>>> regards,
>>>>
>>>> Leonardo Uribe
>>>>
>>>>
>>>> 2016-06-20 14:49 GMT+02:00 Bauke Scholtz <balusc_at_gmail.com>:
>>>>
>>>>> Hi,
>>>>>
>>>>> See https://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-1424
>>>>>
>>>>> This is a commonly requested feature from the community. Several
>>>>> libraries have it implemented such as OmniFaces and PrimeFaces Extensions.
>>>>> It would be nice to offer a standard JSF solution such as
>>>>> <f:importConstants>. It's relatively trivial to implement.
>>>>>
>>>>> If there are no objections, I will take it on me.
>>>>>
>>>>> Cheers, B
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
>