自定义组件上的ValueChangeListener导致PropertyNotFoundException

时间:2012-06-15 12:42:20

标签: jsf jsf-2 el

我们有一个自定义的JSF组件,它以特定的方式呈现一些按钮和一个选择框。这是由扩展UIInput的类完成的。 xhtml模板中使用的自定义组件如下:

<xx:fooComponent
    value="#{fooBean.someProperty}" 
    valueChangeListener="#{fooBean.someMethodInBean}"
    someOtherProperties="true" />

现在我们从运行JSF 2.0的JBoss 4.2.2更改为使用内置JSF库运行的JBoss 7.1.1,它抱怨someMethodInBean不是属性。当然,这不是财产,而是一种方法。世界上谁会将财产绑定到valueChangeListener

起初我以为,这与引用bean的超类中的方法有关,但事实并非如此。将此特定方法添加到FooBean并没有任何区别。

所以我的问题是,他们改变了什么,以便现在突破,我该如何以迁移友好的方式解决它?

修改

组件在我们的*.taglib.xml

中声明为
<!DOCTYPE facelet-taglib PUBLIC
  "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
  "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">

<!-- ... -->
<tag>
    <tag-name>fooComponent</tag-name>       
    <component>
        <component-type>myProject.FooComponent</component-type>                     
    </component>        
</tag>

...导致faces-config.xml中的此声明:

<component>
    <component-type>myProject.FooComponent</component-type>
    <component-class>com.myproject.somemore.UIFooComponent</component-class>
</component>

...通向班级UIFooComponent extends UIInput

编辑2

现在taglib xml看起来像这样:

<facelet-taglib version="2.0"
            xmlns="http://java.sun.com/xml/ns/javaee"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd">

<tag>
    <tag-name>fooComponent</tag-name>       
    <component>
        <component-type>myProject.FooComponent</component-type>                     
    </component>
    <attribute>
        <name>valueChangeListener</name>
        <method-signature>void valueChanged(javax.faces.event.ValueChangeEvent)</method-signature>  
    </attribute>        
</tag>
</facelet-taglib>

但是,他抱怨fooBean没有财产someMethodInBean

编辑3

堆栈跟踪是:

Caused by: javax.el.ELException: /abc/abc.xhtml: The class 'com.myproject.managedbeans.foo.FooBean' does not have the property 'someMethodInBean'.
    at com.sun.faces.facelets.compiler.AttributeInstruction.write(AttributeInstruction.java:94)
    at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:302)
    at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
    at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
    at org.apache.myfaces.tomahawk.application.ResourceViewHandlerWrapper.renderView(ResourceViewHandlerWrapper.java:93)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
    ... 21 more

1 个答案:

答案 0 :(得分:4)

这表明tag属性未在<method-signature>文件的组件<tag>声明中声明为.taglib.xml,如下所示:

<attribute>
    <name>valueChangeListener</name>
    <method-signature>void valueChange(javax.faces.event.ValueChangeEvent)</method-signature>
</attribute>

确保按上述方式正确声明。


更新:您需要确保已声明.taglib.xml文件符合JSF 2.x Facelets XSD(因此 DTD为它出现在传统的Facelets 1.x)中。

<facelet-taglib
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
    version="2.0"
>

    <!-- Tags here -->

</facelet-taglib>