复合组件中的myfaces动作方法抛出

时间:2013-02-17 04:01:13

标签: jsf jsf-2 composite-component myfaces

我遇到了myfaces 2.1.10(与TomEE打包在一起)涉及复合组件和操作方法的奇怪问题。从本质上讲,看下面的例子,myfaces似乎是action方法是一个属性而是抛出一个ElException。这个相同的代码适用于Mojarra(在jBoss 7.1.2下)。

知道我做错了吗?

例外:

    javax.el.ELException: /index.xhtml: Property 'act' not found on type com.company.dept.beans.SomeBean
org.apache.myfaces.view.facelets.compiler.AttributeInstruction.write(AttributeInstruction.java:55)
    org.apache.myfaces.view.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:46)
    org.apache.myfaces.view.facelets.compiler.UILeaf.encodeAll(UILeaf.java:505)
    javax.faces.component.UIComponentBase.encodeAll(UIComponentBase.java:541)
    javax.faces.component.UIComponentBase.encodeAll(UIComponentBase.java:541)
    org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1981)
    org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:285)
    javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:59)
    org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:116)
    org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:241)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:199)

名为“menu”的复合组件:

    <composite:interface displayName="Navigation Menu Bar" shortDescription="Navigation menu bar">          
        <composite:attribute name="action" method-signature="java.lang.String action()"/>
    </composite:interface>

    <composite:implementation>
    <div id="#{cc.clientId}:menuComponent">
        <h:form>
            <h:commandButton action="#{cc.attrs.action}" value="execute action" />
        </h:form>
    </div>
    </composite:implementation>

以下页面使用上面的组件

<h:head>
</h:head>
<h:body>
  <menu:menu action="#{someBean.act}"/>
</h:body>
</html>

带有操作方法的支持bean

package com.company.dept.beans;

import javax.inject.Named;

@Named
public class SomeBean { 

    public String act() {
        System.out.println("ACT CALLED");
        return "SUCCESS";
    }

}

1 个答案:

答案 0 :(得分:0)

这是由于应用程序的打包方式。其中一个包含xhtml的jar文件缺少faces-config.xml文件,导致MyFaces无法找到它。奇怪的是,莫哈拉似乎并不在意......