组合组件throws中的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)

名为"菜单"的复合组件:

    <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>

具有动作方法的支撑豆

package com.company.dept.beans;
import javax.inject.Named;
@Named
public class SomeBean { 
    public String act() {
        System.out.println("ACT CALLED");
        return "SUCCESS";
    }
}

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

相关内容

  • 没有找到相关文章