You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Mario Ivankovits (JIRA)" <my...@incubator.apache.org> on 2005/07/15 08:05:09 UTC

[jira] Created: (MYFACES-334) aliasbean and alias usage in binding

aliasbean and alias usage in binding
------------------------------------

         Key: MYFACES-334
         URL: http://issues.apache.org/jira/browse/MYFACES-334
     Project: MyFaces
        Type: Bug
    Versions: 1.0.9 beta    
    Reporter: Mario Ivankovits


Myfaces fails to restore a view it it uses aliases in bindings.

Our jsf looks like this (for sure, we use include for the dataTable):

<x:aliasBeansScope>
   <x:aliasBean alias="#{coTopicEdit}" value="#{coAddressEdit}" />
   <h:dataTable var="topic" value="#{coTopicEdit.topics}"
               binding="#{coTopicEdit.genericTopicTable}" >
....
   </h:dataTable>
   <h:commandLink value="xx"/>
</x:aliasBeansScope>


The page renders correctly for the first time, but if you press the commandLink myfaces fails in the restoreView phase.
The reason is simple:
During LifecycleImpl.restoreView myfaces tries to attach each component to the backing bean (in recursivelyHandleComponentReferencesAndSetValid - "binding.setValue").
Now if it comes to the binding of the dataTable the alias bean havent had the chance to reassign its alias and thus the ValueBinding for "#{coTopicEdit.genericTopicTable}" fails.


To workaround it I create my own ViewHandler (code follows).
I hooked into restoreView - process the view recursivley and call "makeAlias" on each alias bean using reflection (the method is package private).
This IS a hack and (I think) it breaks the scope of the alias , but for now I am happy with it.

Any ideas how to solve it correctly?

And now the code in case someone else needs it too:

   public UIViewRoot restoreView(FacesContext facesContext, String viewId)
   {
       UIViewRoot root = super.restoreView(facesContext, viewId);
       if (root != null)
       {
           processAliases(facesContext, root);
       }
       return root;
   }

   protected void processAliases(FacesContext context, UIComponent root)
   {
       if (root == null)
       {
           return;
       }

       for (Iterator it = root.getFacetsAndChildren(); it.hasNext(); )
       {
           UIComponent component = (UIComponent)it.next();

           if (component instanceof AliasBean)
           {
               AliasBean alias = (AliasBean) component;
               try
               {
                   Method makeAliasMethod = alias.getClass().getDeclaredMethod("makeAlias", FacesContext.class);
                   makeAliasMethod.setAccessible(true);
                   makeAliasMethod.invoke(alias, context);
               }
               catch (NoSuchMethodException e)
               {
                   log.warn(e.getLocalizedMessage(), e);
               }
               catch (IllegalAccessException e)
               {
                   log.warn(e.getLocalizedMessage(), e);
               }
               catch (InvocationTargetException e)
               {
                   log.warn(e.getLocalizedMessage(), e);
               }
           }

           processAliases(context, component);
       }
   }


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Closed: (MYFACES-334) aliasbean and alias usage in binding

Posted by "Mathias Broekelmann (JIRA)" <my...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/MYFACES-334?page=all ]
     
Mathias Broekelmann closed MYFACES-334:
---------------------------------------

    Resolution: Won't Fix

component bindings are resolved at creation time of the component and is out of scope of the alias bean component. JSF allows you to create only one component instance for one jsf tag. 

If you just need to access the component instance try to use a managed bean which acts as an interface between the component and the aliased bean. The component instance is stored in the non aliased bean and the aliased bean uses the non aliased bean to access the component instance.

Hope that helps.

> aliasbean and alias usage in binding
> ------------------------------------
>
>          Key: MYFACES-334
>          URL: http://issues.apache.org/jira/browse/MYFACES-334
>      Project: MyFaces
>         Type: Bug
>     Versions: 1.0.9 beta
>     Reporter: Mario Ivankovits

>
> Myfaces fails to restore a view it it uses aliases in bindings.
> Our jsf looks like this (for sure, we use include for the dataTable):
> <x:aliasBeansScope>
>    <x:aliasBean alias="#{coTopicEdit}" value="#{coAddressEdit}" />
>    <h:dataTable var="topic" value="#{coTopicEdit.topics}"
>                binding="#{coTopicEdit.genericTopicTable}" >
> ....
>    </h:dataTable>
>    <h:commandLink value="xx"/>
> </x:aliasBeansScope>
> The page renders correctly for the first time, but if you press the commandLink myfaces fails in the restoreView phase.
> The reason is simple:
> During LifecycleImpl.restoreView myfaces tries to attach each component to the backing bean (in recursivelyHandleComponentReferencesAndSetValid - "binding.setValue").
> Now if it comes to the binding of the dataTable the alias bean havent had the chance to reassign its alias and thus the ValueBinding for "#{coTopicEdit.genericTopicTable}" fails.
> To workaround it I create my own ViewHandler (code follows).
> I hooked into restoreView - process the view recursivley and call "makeAlias" on each alias bean using reflection (the method is package private).
> This IS a hack and (I think) it breaks the scope of the alias , but for now I am happy with it.
> Any ideas how to solve it correctly?
> And now the code in case someone else needs it too:
>    public UIViewRoot restoreView(FacesContext facesContext, String viewId)
>    {
>        UIViewRoot root = super.restoreView(facesContext, viewId);
>        if (root != null)
>        {
>            processAliases(facesContext, root);
>        }
>        return root;
>    }
>    protected void processAliases(FacesContext context, UIComponent root)
>    {
>        if (root == null)
>        {
>            return;
>        }
>        for (Iterator it = root.getFacetsAndChildren(); it.hasNext(); )
>        {
>            UIComponent component = (UIComponent)it.next();
>            if (component instanceof AliasBean)
>            {
>                AliasBean alias = (AliasBean) component;
>                try
>                {
>                    Method makeAliasMethod = alias.getClass().getDeclaredMethod("makeAlias", FacesContext.class);
>                    makeAliasMethod.setAccessible(true);
>                    makeAliasMethod.invoke(alias, context);
>                }
>                catch (NoSuchMethodException e)
>                {
>                    log.warn(e.getLocalizedMessage(), e);
>                }
>                catch (IllegalAccessException e)
>                {
>                    log.warn(e.getLocalizedMessage(), e);
>                }
>                catch (InvocationTargetException e)
>                {
>                    log.warn(e.getLocalizedMessage(), e);
>                }
>            }
>            processAliases(context, component);
>        }
>    }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (MYFACES-334) aliasbean and alias usage in binding

Posted by "Mario Ivankovits (JIRA)" <de...@myfaces.apache.org>.
     [ http://issues.apache.org/jira/browse/MYFACES-334?page=all ]

Mario Ivankovits updated MYFACES-334:
-------------------------------------

    Resolution: Fixed

> aliasbean and alias usage in binding
> ------------------------------------
>
>          Key: MYFACES-334
>          URL: http://issues.apache.org/jira/browse/MYFACES-334
>      Project: MyFaces Core
>         Type: Bug
>     Versions: 1.0.9m9
>     Reporter: Mario Ivankovits
>     Assignee: Martin Marinschek

>
> Myfaces fails to restore a view it it uses aliases in bindings.
> Our jsf looks like this (for sure, we use include for the dataTable):
> <x:aliasBeansScope>
>    <x:aliasBean alias="#{coTopicEdit}" value="#{coAddressEdit}" />
>    <h:dataTable var="topic" value="#{coTopicEdit.topics}"
>                binding="#{coTopicEdit.genericTopicTable}" >
> ....
>    </h:dataTable>
>    <h:commandLink value="xx"/>
> </x:aliasBeansScope>
> The page renders correctly for the first time, but if you press the commandLink myfaces fails in the restoreView phase.
> The reason is simple:
> During LifecycleImpl.restoreView myfaces tries to attach each component to the backing bean (in recursivelyHandleComponentReferencesAndSetValid - "binding.setValue").
> Now if it comes to the binding of the dataTable the alias bean havent had the chance to reassign its alias and thus the ValueBinding for "#{coTopicEdit.genericTopicTable}" fails.
> To workaround it I create my own ViewHandler (code follows).
> I hooked into restoreView - process the view recursivley and call "makeAlias" on each alias bean using reflection (the method is package private).
> This IS a hack and (I think) it breaks the scope of the alias , but for now I am happy with it.
> Any ideas how to solve it correctly?
> And now the code in case someone else needs it too:
>    public UIViewRoot restoreView(FacesContext facesContext, String viewId)
>    {
>        UIViewRoot root = super.restoreView(facesContext, viewId);
>        if (root != null)
>        {
>            processAliases(facesContext, root);
>        }
>        return root;
>    }
>    protected void processAliases(FacesContext context, UIComponent root)
>    {
>        if (root == null)
>        {
>            return;
>        }
>        for (Iterator it = root.getFacetsAndChildren(); it.hasNext(); )
>        {
>            UIComponent component = (UIComponent)it.next();
>            if (component instanceof AliasBean)
>            {
>                AliasBean alias = (AliasBean) component;
>                try
>                {
>                    Method makeAliasMethod = alias.getClass().getDeclaredMethod("makeAlias", FacesContext.class);
>                    makeAliasMethod.setAccessible(true);
>                    makeAliasMethod.invoke(alias, context);
>                }
>                catch (NoSuchMethodException e)
>                {
>                    log.warn(e.getLocalizedMessage(), e);
>                }
>                catch (IllegalAccessException e)
>                {
>                    log.warn(e.getLocalizedMessage(), e);
>                }
>                catch (InvocationTargetException e)
>                {
>                    log.warn(e.getLocalizedMessage(), e);
>                }
>            }
>            processAliases(context, component);
>        }
>    }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Closed: (MYFACES-334) aliasbean and alias usage in binding

Posted by "Mario Ivankovits (JIRA)" <de...@myfaces.apache.org>.
     [ http://issues.apache.org/jira/browse/MYFACES-334?page=all ]
     
Mario Ivankovits closed MYFACES-334:
------------------------------------


> aliasbean and alias usage in binding
> ------------------------------------
>
>          Key: MYFACES-334
>          URL: http://issues.apache.org/jira/browse/MYFACES-334
>      Project: MyFaces Core
>         Type: Bug
>     Versions: 1.0.9m9
>     Reporter: Mario Ivankovits
>     Assignee: Martin Marinschek

>
> Myfaces fails to restore a view it it uses aliases in bindings.
> Our jsf looks like this (for sure, we use include for the dataTable):
> <x:aliasBeansScope>
>    <x:aliasBean alias="#{coTopicEdit}" value="#{coAddressEdit}" />
>    <h:dataTable var="topic" value="#{coTopicEdit.topics}"
>                binding="#{coTopicEdit.genericTopicTable}" >
> ....
>    </h:dataTable>
>    <h:commandLink value="xx"/>
> </x:aliasBeansScope>
> The page renders correctly for the first time, but if you press the commandLink myfaces fails in the restoreView phase.
> The reason is simple:
> During LifecycleImpl.restoreView myfaces tries to attach each component to the backing bean (in recursivelyHandleComponentReferencesAndSetValid - "binding.setValue").
> Now if it comes to the binding of the dataTable the alias bean havent had the chance to reassign its alias and thus the ValueBinding for "#{coTopicEdit.genericTopicTable}" fails.
> To workaround it I create my own ViewHandler (code follows).
> I hooked into restoreView - process the view recursivley and call "makeAlias" on each alias bean using reflection (the method is package private).
> This IS a hack and (I think) it breaks the scope of the alias , but for now I am happy with it.
> Any ideas how to solve it correctly?
> And now the code in case someone else needs it too:
>    public UIViewRoot restoreView(FacesContext facesContext, String viewId)
>    {
>        UIViewRoot root = super.restoreView(facesContext, viewId);
>        if (root != null)
>        {
>            processAliases(facesContext, root);
>        }
>        return root;
>    }
>    protected void processAliases(FacesContext context, UIComponent root)
>    {
>        if (root == null)
>        {
>            return;
>        }
>        for (Iterator it = root.getFacetsAndChildren(); it.hasNext(); )
>        {
>            UIComponent component = (UIComponent)it.next();
>            if (component instanceof AliasBean)
>            {
>                AliasBean alias = (AliasBean) component;
>                try
>                {
>                    Method makeAliasMethod = alias.getClass().getDeclaredMethod("makeAlias", FacesContext.class);
>                    makeAliasMethod.setAccessible(true);
>                    makeAliasMethod.invoke(alias, context);
>                }
>                catch (NoSuchMethodException e)
>                {
>                    log.warn(e.getLocalizedMessage(), e);
>                }
>                catch (IllegalAccessException e)
>                {
>                    log.warn(e.getLocalizedMessage(), e);
>                }
>                catch (InvocationTargetException e)
>                {
>                    log.warn(e.getLocalizedMessage(), e);
>                }
>            }
>            processAliases(context, component);
>        }
>    }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Reopened: (MYFACES-334) aliasbean and alias usage in binding

Posted by "Mario Ivankovits (JIRA)" <de...@myfaces.apache.org>.
     [ http://issues.apache.org/jira/browse/MYFACES-334?page=all ]
     
Mario Ivankovits reopened MYFACES-334:
--------------------------------------

     Assign To: Mario Ivankovits

> aliasbean and alias usage in binding
> ------------------------------------
>
>          Key: MYFACES-334
>          URL: http://issues.apache.org/jira/browse/MYFACES-334
>      Project: MyFaces Core
>         Type: Bug
>     Versions: 1.0.9m9
>     Reporter: Mario Ivankovits
>     Assignee: Mario Ivankovits

>
> Myfaces fails to restore a view it it uses aliases in bindings.
> Our jsf looks like this (for sure, we use include for the dataTable):
> <x:aliasBeansScope>
>    <x:aliasBean alias="#{coTopicEdit}" value="#{coAddressEdit}" />
>    <h:dataTable var="topic" value="#{coTopicEdit.topics}"
>                binding="#{coTopicEdit.genericTopicTable}" >
> ....
>    </h:dataTable>
>    <h:commandLink value="xx"/>
> </x:aliasBeansScope>
> The page renders correctly for the first time, but if you press the commandLink myfaces fails in the restoreView phase.
> The reason is simple:
> During LifecycleImpl.restoreView myfaces tries to attach each component to the backing bean (in recursivelyHandleComponentReferencesAndSetValid - "binding.setValue").
> Now if it comes to the binding of the dataTable the alias bean havent had the chance to reassign its alias and thus the ValueBinding for "#{coTopicEdit.genericTopicTable}" fails.
> To workaround it I create my own ViewHandler (code follows).
> I hooked into restoreView - process the view recursivley and call "makeAlias" on each alias bean using reflection (the method is package private).
> This IS a hack and (I think) it breaks the scope of the alias , but for now I am happy with it.
> Any ideas how to solve it correctly?
> And now the code in case someone else needs it too:
>    public UIViewRoot restoreView(FacesContext facesContext, String viewId)
>    {
>        UIViewRoot root = super.restoreView(facesContext, viewId);
>        if (root != null)
>        {
>            processAliases(facesContext, root);
>        }
>        return root;
>    }
>    protected void processAliases(FacesContext context, UIComponent root)
>    {
>        if (root == null)
>        {
>            return;
>        }
>        for (Iterator it = root.getFacetsAndChildren(); it.hasNext(); )
>        {
>            UIComponent component = (UIComponent)it.next();
>            if (component instanceof AliasBean)
>            {
>                AliasBean alias = (AliasBean) component;
>                try
>                {
>                    Method makeAliasMethod = alias.getClass().getDeclaredMethod("makeAlias", FacesContext.class);
>                    makeAliasMethod.setAccessible(true);
>                    makeAliasMethod.invoke(alias, context);
>                }
>                catch (NoSuchMethodException e)
>                {
>                    log.warn(e.getLocalizedMessage(), e);
>                }
>                catch (IllegalAccessException e)
>                {
>                    log.warn(e.getLocalizedMessage(), e);
>                }
>                catch (InvocationTargetException e)
>                {
>                    log.warn(e.getLocalizedMessage(), e);
>                }
>            }
>            processAliases(context, component);
>        }
>    }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (MYFACES-334) aliasbean and alias usage in binding

Posted by "Anonymous (JIRA)" <de...@myfaces.apache.org>.
     [ http://issues.apache.org/jira/browse/MYFACES-334?page=all ]

 updated MYFACES-334:
---------------------


> aliasbean and alias usage in binding
> ------------------------------------
>
>          Key: MYFACES-334
>          URL: http://issues.apache.org/jira/browse/MYFACES-334
>      Project: MyFaces Core
>         Type: Bug
>     Versions: 1.0.9m9
>     Reporter: Mario Ivankovits
>     Assignee: Martin Marinschek

>
> Myfaces fails to restore a view it it uses aliases in bindings.
> Our jsf looks like this (for sure, we use include for the dataTable):
> <x:aliasBeansScope>
>    <x:aliasBean alias="#{coTopicEdit}" value="#{coAddressEdit}" />
>    <h:dataTable var="topic" value="#{coTopicEdit.topics}"
>                binding="#{coTopicEdit.genericTopicTable}" >
> ....
>    </h:dataTable>
>    <h:commandLink value="xx"/>
> </x:aliasBeansScope>
> The page renders correctly for the first time, but if you press the commandLink myfaces fails in the restoreView phase.
> The reason is simple:
> During LifecycleImpl.restoreView myfaces tries to attach each component to the backing bean (in recursivelyHandleComponentReferencesAndSetValid - "binding.setValue").
> Now if it comes to the binding of the dataTable the alias bean havent had the chance to reassign its alias and thus the ValueBinding for "#{coTopicEdit.genericTopicTable}" fails.
> To workaround it I create my own ViewHandler (code follows).
> I hooked into restoreView - process the view recursivley and call "makeAlias" on each alias bean using reflection (the method is package private).
> This IS a hack and (I think) it breaks the scope of the alias , but for now I am happy with it.
> Any ideas how to solve it correctly?
> And now the code in case someone else needs it too:
>    public UIViewRoot restoreView(FacesContext facesContext, String viewId)
>    {
>        UIViewRoot root = super.restoreView(facesContext, viewId);
>        if (root != null)
>        {
>            processAliases(facesContext, root);
>        }
>        return root;
>    }
>    protected void processAliases(FacesContext context, UIComponent root)
>    {
>        if (root == null)
>        {
>            return;
>        }
>        for (Iterator it = root.getFacetsAndChildren(); it.hasNext(); )
>        {
>            UIComponent component = (UIComponent)it.next();
>            if (component instanceof AliasBean)
>            {
>                AliasBean alias = (AliasBean) component;
>                try
>                {
>                    Method makeAliasMethod = alias.getClass().getDeclaredMethod("makeAlias", FacesContext.class);
>                    makeAliasMethod.setAccessible(true);
>                    makeAliasMethod.invoke(alias, context);
>                }
>                catch (NoSuchMethodException e)
>                {
>                    log.warn(e.getLocalizedMessage(), e);
>                }
>                catch (IllegalAccessException e)
>                {
>                    log.warn(e.getLocalizedMessage(), e);
>                }
>                catch (InvocationTargetException e)
>                {
>                    log.warn(e.getLocalizedMessage(), e);
>                }
>            }
>            processAliases(context, component);
>        }
>    }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira