0

我在涉及复合组件和操作方法的 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>

带有 action 方法的 backing bean

package com.company.dept.beans;

import javax.inject.Named;

@Named
public class SomeBean { 

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

}
4

1 回答 1

0

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

于 2013-11-15T14:34:10.700 回答