当我尝试扩展 primefaces fileupload 时,侦听器属性值在 getListener() 中解析为 ValueExpression,并抛出 PropertyNotFoundException。
我的环境:
这里有例外:
Caused by: jakarta.el.PropertyNotFoundException: The class 'org.test.component.FileUploadBean_ClientProxy' does not have the property 'upload'.
at jakarta.el.BeanELResolver.getBeanProperty(BeanELResolver.java:626)
at jakarta.el.BeanELResolver.getValue(BeanELResolver.java:338)
at jakarta.el.CompositeELResolver.getValue(CompositeELResolver.java:136)
at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:190)
at org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpression.getValue(ContextAwareTagValueExpression.java:100)
... 50 more
它与 quarkus (3.6.5)、primefaces 13.0.3、myfaces 4.0.1 一起使用。 但我在 Tomcat 10、primefaces 13.0.3、jakarta.faces 4.0.5、weld-servlet-shaded 4.0.0.Final 中也遇到了同样的问题。
如果我直接使用primefaces组件
有没有办法让它使用@FacesComponent 工作。
这是我的自定义文件上传:
@FacesComponent(value = "org.test.component.FileUpload", tagName = "fileUpload", namespace = "mycomponents", createTag = true)
public class FileUpload extends org.primefaces.component.fileupload.FileUpload {}
具有上传方法的java bean:
@Named
@RequestScoped
public class FileUploadBean implements Serializable {
public void upload(FileUploadEvent event) {
System.out.println("Upload: " + event.getFile().getFileName());
}
}
xhtml 页面:
<!DOCTYPE html>
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:faces="jakarta.faces"
xmlns:ui="jakarta.faces.facelets"
xmlns:f="jakarta.faces.core"
xmlns:h="jakarta.faces.html"
xmlns:p="http://primefaces.org/ui"
xmlns:w="mycomponents"
>
<h:head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Test</title>
</h:head>
<h:body>
<h:form enctype="multipart/form-data">
<!-- Get PropertyNotFoundExpression -->
<w:fileUpload listener="#{fileUploadBean.upload}" auto="true"/>
<!-- Works fine -->
<p:fileUpload listener="#{fileUploadBean.upload}" auto="true"/>
</h:form>
</h:body>
</html>
我尝试使用以下EL
#{fileUploadBean.upload(event)}
调用了上传方法,但事件为空。
我通过使用 taglib xml 文件和 primefaces 文件上传处理程序让它工作。
在“mycomponents.taglib.xml”中:
<facelet-taglib version="4.0"
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-facelettaglibrary_4_0.xsd"
>
<namespace>mycomponents</namespace>
<tag>
<tag-name>fileUpload</tag-name>
<component>
<component-type>org.test.component.FileUpload</component-type>
<handler-class>org.primefaces.component.fileupload.FileUploadHandler</handler-class>
</component>
</tag>
</facelet-taglib>
在自定义组件“FileUpload.java”中:
@FacesComponent(value = "org.test.component.FileUpload")
public class FileUpload extends org.primefaces.component.fileupload.FileUpload {}
我很确定还有其他解决方案,但目前如果找到的话这是最好的。