我在将方法参数传递给嵌套复合组件时遇到问题。
我有第一个组件 wose 复合:界面看起来像:
<composite:interface>
<composite:attribute name="onRowEditListener" required="false" method-signature="void listener(org.primefaces.event.RowEditEvent)"/>
</composite:interface>
它使用另一个具有类似界面的复合组件组件。
第一级组件是这样使用的:
<mynamespace:compo1 onRowEditListener=#{bean.method}"/>
嵌套的是这样使用的:
<mynamespace:compo2 onRowEditListener=#{cc.attrs.onRowEditListener}"/>
如果我插入两个控件,我得到:
- 在第一级控制中,像 org.apache.el.MethodExpressionImpl@358f0647 这样的输出,对我来说看起来不错
- 在第二(嵌套)级别控件中,输出类似于 org.apache.myfaces.view.facelets.el.LocationValueExpression@ff381f45 。
引发的异常如下所示:
19/07/2012 19:39:02 fr.senat.faces.exceptions.DetailedExceptionHandler INFO [DetailedExceptionHandler.java:40] [http-8080-7] - Stack trace: javax.faces.FacesException: Exception while calling broadcast on component : {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /editSenateur.xhtml][Class: javax.faces.component.html.HtmlBody,Id: j_id_5][Class: org.primefaces.component.layout.Layout,Id: j_id_6][Class: org.primefaces.component.layout.LayoutUnit,Id: j_id_v][Class: org.primefaces.component.outputpanel.OutputPanel,Id: detailCommissions][Class: javax.faces.component.html.HtmlForm,Id: j_id_x][Class: org.primefaces.component.tabview.TabView,Id: tabFonctionsInternes][Class: org.primefaces.component.tabview.Tab,Id: fonctionsCommissions][Class: javax.faces.component.UINamingContainer,Id: j_id_10][Class: javax.faces.component.UIPanel,Id: j_idj_id_10__f_cc_facet][Class: org.primefaces.component.outputpanel.OutputPanel,Id: panelTabViewCommissions][Class: org.primefaces.component.tabview.TabView,Id: tabViewCommissions][Class: org.primefaces.component.tabview.Tab,Id: commissionTab][Class: org.primefaces.component.panelgrid.PanelGrid,Id: j_id_15][Class: org.primefaces.component.row.Row,Id: j_id_1b][Class: org.primefaces.component.column.Column,Id: j_id_1c][Class: javax.faces.component.UINamingContainer,Id: j_id_1d][Class: javax.faces.component.UIPanel,Id: j_idj_id_1d__f_cc_facet][Class: org.primefaces.component.datatable.DataTable,Id: sheetFonctions]} created from: /resources/sen/fonctionsCommission.xhtml at line 27 and column 162
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:430)
at javax.faces.component.UIData.broadcast(UIData.java:1610)
at javax.faces.component.UIData.broadcast(UIData.java:1596)
at javax.faces.component.UIData.broadcast(UIData.java:1596)
at javax.faces.component.UIData.broadcast(UIData.java:1596)
at javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:1023)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:286)
at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1360)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:752)
at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:38)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:170)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
at org.apache.myfaces.extensions.cdi.jsf2.impl.listener.phase.CodiLifecycleWrapper.execute(CodiLifecycleWrapper.java:95)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:357)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at fr.senat.faces.filters.HibernateSessionConversationFilter.doFilter(HibernateSessionConversationFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.apache.myfaces.view.facelets.el.ContextAwareELException: javax.el.ELException: java.lang.IllegalArgumentException: wrong number of arguments
at org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression.invoke(ContextAwareTagMethodExpression.java:108)
at org.primefaces.component.behavior.ajax.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxBehaviorListenerImpl.java:42)
at org.primefaces.event.RowEditEvent.processListener(RowEditEvent.java:41)
at javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:74)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:406)
... 31 more
Caused by: javax.el.ELException: java.lang.IllegalArgumentException: wrong number of arguments
at org.apache.el.parser.AstValue.invoke(AstValue.java:195)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
at org.apache.myfaces.view.facelets.el.ValueExpressionMethodExpression.invoke(ValueExpressionMethodExpression.java:68)
at org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression.invoke(ContextAwareTagMethodExpression.java:96)
... 35 more
Caused by: java.lang.IllegalArgumentException: wrong number of arguments
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.el.parser.AstValue.invoke(AstValue.java:191)
... 38 more
看起来该方法已正确传递给第一个控件,但是当传递给第二个控件时,EL 表达式会得到一个项目符号......
我在用 :
- 我的面孔 2.1.7
- 雄猫 6.0.33
在此先感谢您的帮助。
更新
我可以评估的唯一“进步”是一个kludge ...
杂牌类:
/**
*
* @author lpenet
*
* This class is a workaround kluge. Methods passed as a parameter to a
* composite component then to a PrimeFaces p:ajax seems to get a bullet
* somewhere in the process, at least with Tomcat 6 + MyFaces
* 2.1 + CODI 1.0.5 + OpenWebbeans 1.0.3 See :
* http://forum.primefaces.org/viewtopic.php?f=3&t=23558&p=72885#p72885
*
* Using this class as "componentType", one can forward the methode call.
*
* Not so nice, but... works.
*
*/
@FacesComponent(value = "fr.senat.beans.PrimefacesListenerKludge")
public class PrimefacesListenerKludge extends UINamingContainer {
@Override
public String getFamily() {
return "javax.faces.NamingContainer"; // Important! Required for
// composite components.
}
public void forwardRowEditListener(RowEditEvent event) {
FacesContext context = FacesContext.getCurrentInstance();
Object listener = getAttributes().get("onRowEditListener");
if (listener == null) {
return;
}
MethodExpression ajaxEventListener = (MethodExpression) listener;
ajaxEventListener
.invoke(context.getELContext(), new Object[] { event });
}
}
样品用途:
<composite:interface componentType="fr.senat.beans.PrimefacesListenerKludge">
...
<composite:attribute name="onRowEditListener" required="false"
method-signature="void listener(org.primefaces.event.RowEditEvent)"
default="#{cc.parent.attrs.onRowEditListener}" />
</composite:interface>
<composite:implementation>
...
</composite:implementation>
老实说,我不知道我当前的堆栈(PrimeFaces 4/MyFaces 2.1.13/OWB 1.2.1/Tomcat 7.0.32)是否仍然需要它,但没有时间进行测试。