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

[jsr344-experts] PRD Review and pending issues (Please reopen JAVASERVERFACES_SPEC_PUBLIC-922 because AttachedObjectHandler.ATTACHED_OBJECT_HANDLERS_KEY is inconsistent)

From: Leonardo Uribe <lu4242_at_gmail.com>
Date: Wed, 23 Jan 2013 21:50:40 -0500

Hi

Checking the spec javadoc I notice the introduction of this constant:

AttachedObjectHandler.ATTACHED_OBJECT_HANDLERS_KEY

With this description:

"... The key in the value set of the composite component BeanDescriptor,
the value for which is a List<AttachedObjectHandler>. ..."

The spec issue is this:

http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-922

In few words, that constant does not have any sense and should be removed.
I suppose it try to do the same as
AttachedObjectTarget.ATTACHED_OBJECT_TARGETS_KEY, but after thinking a lot
about it these two are different cases.

The idea behind AttachedObjectTarget.ATTACHED_OBJECT_TARGETS_KEY is keep a
list of the "targets" or in other words the components and the behavior that
can be applied to those components. In that sense, there is one interface for
ActionSouce2, other for ClientBehavior and so on.

In order to be included in AttachedObjectTarget.ATTACHED_OBJECT_TARGETS_KEY
list, the implementations of AttachedObjectTarget are suppose to be
Serializable. Additionally, the definition of the targets is done when
vdl.getComponentMetadata() call is done, and that list does not change
across composite component instances of the same kind.

But AttachedObjectHandler.ATTACHED_OBJECT_HANDLERS_KEY is a complete
different story by these reasons:

- First of all, the instances of AttachedObjectHandler are not
  Serializable, and it can't be because usually it refers to a some facelet
  TagHandler instance.
- The idea behind UIComponent.BEANINFO_KEY or the composite component
  BeanDescriptor is that the information there is related to the composite
  component itself and not on the specific composite component instance.
  For example:

<myCCLib:customButton ...>
   <f:actionListener for="buttonA" .../>
</myCCLib:customButton>

  Generates a list of AttachedObjectHandler with the actionListener TagHandler.

<myCCLib:customButton ... />

  Does not generate any list.

  Ignoring the first reason, the right place to put this information is not
  the composite component bean description, instead it is the composite
  component attribute map.
- The list of AttachedObjectHandler is only relevant when the composite
  component is being populated, specifically for this method in
  ViewDeclarationLanguage:

    public void retargetAttachedObjects(FacesContext context,
             UIComponent topLevelComponent, List<AttachedObjectHandler> handlers)

  This method is just executed once, because you can't add a
  AttachedObjectHandler to a composite component once is already populated.

The right thing to do is create a method in ViewDeclarationLanguage like this:

   public void addAttachedObjectHandler(FacesContext context,
         UIComponent compositeComponentParent, AttachedObjectHandler handler)
                
In this way you can do what JAVASERVERFACES_SPEC_PUBLIC-922 wants: allow create
a tag handler for AttachedObjectHandler instances like f:actionListener or
f:clientBehavior or whatever outside JSF implementation.

regards,

Leonardo Uribe