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

Leonardo Uribe commented on MYFACES-3613:
-----------------------------------------

I have seen this problem many times. The recommended solution until this time 
is use "targets" syntax:

<cc:interface>
<cc:attribute name="action" targets="mybutton"/>
        <cc:attribute name="value"/>
        <cc:actionSource targets="mybutton"/>
</cc:interface>
<cc:implementation>
<h:commandButton id="mybutton" value="#{cc.attrs.value}" immediate="true">
<cc:insertChildren/>
</h:commandButton>
</cc:implementation> 

This syntax is the one initially designed in JSF 2.0 spec.

But thinking more about it, it sounds reasonable to avoid the 
NullPointerException on ValueExpressionMethodExpression, which do the "bridge" 
between source #{cc.attr....} declaration and the ValueExpression chain, that 
finally ends in the final MethodExpression. In that way, h:commandButton will 
have a "dummy" invocation, but if you provide a method expression in the 
composite component attribute map, it will be redirected without any user 
intervention. 

I can't imagine any side effects doing this change, and it will be friendly for 
users. Also, there are some cases where this behavior is wanted and "targets" 
syntax needs to be avoided (non NamingContainer  composite component and inner 
components with generated ids). According to user reports, it will help with 
migration from facelets templates to composite components.

If no objections I'll commit the proposed solution soon.
                
> NPE in composite component when ActionListener is missing in the source
> -----------------------------------------------------------------------
>
>                 Key: MYFACES-3613
>                 URL: https://issues.apache.org/jira/browse/MYFACES-3613
>             Project: MyFaces Core
>          Issue Type: Bug
>    Affects Versions: 2.1.8
>         Environment: Java 1.7_05 Win32, Servlet3.0, Jetty8.1.5.v20120716
>            Reporter: marco fago
>         Attachments: MYFACES-3613-1.patch
>
>
> Consider the following component (simpleCommandButton.xhtml)
> <ui:component xmlns="http://www.w3.org/1999/xhtml"; 
>       xmlns:ui="http://java.sun.com/jsf/facelets";
>       xmlns:h="http://java.sun.com/jsf/html"; 
>       xmlns:p="http://primefaces.org/ui";      
>       xmlns:cc="http://java.sun.com/jsf/composite";
>       >
>       <cc:interface>
>               <cc:attribute name="action"/>
>               <cc:attribute name="actionListener"/>
>         <cc:attribute name="value"/>        
>       </cc:interface>
>       <cc:implementation>             
>               <h:commandButton value="#{cc.attrs.value}" 
> action="#{cc.attrs.action}" actionListener="#{cc.attrs.actionListener}" 
> immediate="true">                    
>                       <cc:insertChildren/>
>               </h:commandButton>
>       </cc:implementation>
> </ui:component>
> And in your page:
> <myLib::simpleCommandButton value="Test" action="exit"/>
> When clicking on the button a NPE occurs:
> java.lang.NullPointerException
>       at 
> org.apache.myfaces.view.facelets.el.ValueExpressionMethodExpression.invoke(ValueExpressionMethodExpression.java:68)
>       at 
> org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression.invoke(ContextAwareTagMethodExpression.java:96)
>       at 
> javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:83)
>       at javax.faces.event.ActionEvent.processListener(ActionEvent.java:51)
>       at 
> javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:418)
>       at javax.faces.component.UICommand.broadcast(UICommand.java:103)
>       at javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:1028)
>       at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:286)
>       at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1375)
>       at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:759)
>       at 
> org.springframework.faces.webflow.FlowLifecycle.invokePhase(FlowLifecycle.java:118)
>       at 
> org.springframework.faces.webflow.FlowLifecycle.execute(FlowLifecycle.java:70)
>       at 
> org.springframework.faces.webflow.JsfView.processUserEvent(JsfView.java:120)
>       at 
> org.springframework.webflow.engine.ViewState.handleEvent(ViewState.java:226)
>       at 
> org.springframework.webflow.engine.ViewState.resume(ViewState.java:196)
>       at org.springframework.webflow.engine.Flow.resume(Flow.java:545)
>       at 
> org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:258)
>       at 
> org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:169)
>       at 
> org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:183)
>       at 
> org.springframework.faces.webflow.JsfFlowHandlerAdapter.handle(JsfFlowHandlerAdapter.java:48)
>       at 
> org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
>       at 
> org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
>       at 
> org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
>       at 
> org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
>       at javax.servlet.http.HttpServlet.service(HttpServlet.java:755)
>       at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
>       at 
> org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:643)
>       at 
> org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1331)
>       at 
> org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
>       at 
> org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1302)
>       at 
> net.sf.ehcache.constructs.web.filter.GzipFilter.doFilter(GzipFilter.java:95)
>       at net.sf.ehcache.constructs.web.filter.Filter.doFilter(Filter.java:86)
>       at 
> org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1302)
>       at 
> org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java
> probably because of the missing (null) attribute "actionListener" in the 
> source declaration.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to