myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leonardo Uribe (JIRA)" <...@myfaces.apache.org>
Subject [jira] [Commented] (MYFACES-3168) Bound attribute values resolve to NULL during PreRenderViewEvent for nested composite components
Date Mon, 20 Jun 2011 21:06:47 GMT

    [ https://issues.apache.org/jira/browse/MYFACES-3168?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13052221#comment-13052221
] 

Leonardo Uribe commented on MYFACES-3168:
-----------------------------------------

Thanks for the example provided. It makes easier to detect what's going on.

The code proposed has a flaw. It is more a side effect, caused by the evaluation of #{cc}
and the fact that the component stack is not set on that location. 

PreRenderViewEvent is an event propagated to UIViewRoot. In this case, you are using a component
to listen to that event, so the component stack is not set and when the expressions are resolved,
they can't found the right composite component instance and the final result is the one you
described.

The solution is very simple to do. Just try this:

	private void processPreRenderViewEvent(PreRenderViewEvent e) throws AbortProcessingException
 {
		
	    FacesContext ctx = getFacesContext();
		
		if(!ctx.isPostback()) {
			
		    this.pushComponentToEL(ctx, this);
		    try
		    {
                              /** .... **/
		    }
		    finally
		    {
		        this.popComponentFromEL(ctx);
		    }
		}

I tested it and it works. I tried to do something on UIViewRoot, but it doesn't seem to be
correct, because it is an event tied to the view, so it should be responsibility of the developer
to set context, in that case put the current component onto the stack.

In other topic, this is a better way to suscribe the event:

@ListenerFor(systemEventClass=PostAddToViewEvent.class)
public class UIComponent1 extends UIComponentBase implements NamingContainer, SystemEventListener
{

	public UIComponent1() {
        }

	@Override
    public void processEvent(ComponentSystemEvent event)
            throws AbortProcessingException
    {
        super.processEvent(event);
        
        if (event instanceof PostAddToViewEvent)
        {
            getFacesContext().getViewRoot().subscribeToViewEvent(PreRenderViewEvent.class,
this);
        }
    }

In few words, use PostAddToViewEvent to suscribe the listener is better because the component
is now attached to the view, so that is the right time to do that. Anyway, do it inside the
constructor works. I'll close this issue as invalid.

> Bound attribute values resolve to NULL during PreRenderViewEvent for nested composite
components
> ------------------------------------------------------------------------------------------------
>
>                 Key: MYFACES-3168
>                 URL: https://issues.apache.org/jira/browse/MYFACES-3168
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: General
>    Affects Versions: 2.0.6, 2.1.0
>         Environment: Windows 7 x64 Enterprise. 
> JDK 1.6.0_25. 
> Eclipse Version: Helios Service Release 2
> Build id: 20110218-0911
>            Reporter: MAtthew Sweeney
>         Attachments: jsf-testing-myfaces.zip, screenshot-1.jpg
>
>
> When nesting custom composite components, any data bound attributes (eg #{someValueExpression}
) will resolve to null during the PreRenderViewEvent. This only occurs on the second level
or deeper nested component (the top-level component in the page works fine).
> This same issue occurs on JSF RI 2.0.4, 2.1.x, 2.2.x
> I have an eclipse project for upload that reproduces the problem.
> I have no cause for the issue at this time.
> Cheers,
> Matt

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message