Java 无法实例化类-p:filedownload在f:setPropertyActionListener之前调用
我在dataTable中有一个fileDownload组件,但当我单击它时,似乎在setPropertyActionListener设置datlis.filepath变量之前调用了filedownloader 当我点击下载时,我得到“不能实例化类:ui.FileDownloader.com.sun.faces.mgbean.ManagedBeanCreationException:Cant实例化类:ui.FileDownloader。” 我的jsf代码是:Java 无法实例化类-p:filedownload在f:setPropertyActionListener之前调用,java,primefaces,download,Java,Primefaces,Download,我在dataTable中有一个fileDownload组件,但当我单击它时,似乎在setPropertyActionListener设置datlis.filepath变量之前调用了filedownloader 当我点击下载时,我得到“不能实例化类:ui.FileDownloader.com.sun.faces.mgbean.ManagedBeanCreationException:Cant实例化类:ui.FileDownloader。” 我的jsf代码是: <p:column header
<p:column headerText="Metadata" style="width:40px">
<p:commandButton id="selectButton" rendered="#{datlis.has_metadata}" icon="ui-icon-circle-arrow-s" title="View" ajax="false" >
<f:setPropertyActionListener value="#{datlis.filepath}" target="#{filedownloader.filepath}" />
<p:fileDownload value="#{filedownloader.file}" />
</p:commandButton>
</p:column>
堆栈跟踪提到了一个关于inputstream的nullpointer异常,这就是为什么我认为没有设置'filepath'变量——加上我的系统输出只显示system.out.println中的“100”,并且setFilepath函数没有系统输出……就好像根本没有调用它一样
我也试过:
<p:column headerText="Metadata" style="width:40px">
<p:commandButton id="selectButton" rendered="#{datlis.has_metadata}" icon="ui-icon-circle-arrow-s" title="View" ajax="false" >
<f:param name="filepath" value="#{datlis.filepath}" />
<p:fileDownload value="#{filedownloader.file}" />
</p:commandButton>
</p:column>
但这似乎也不起作用。有什么想法吗?我觉得我在正确的轨道上也许只是误用了元素 管理的财产将在施工后注入。因此,如果您尝试在bean的构造函数中访问它们,您将得到一个NPE 使用带有
@PostConstruct
注释的方法。它将在构造和属性注入后自动调用:
@PostConstruct
public void init() {
// do your initializations here
}
谢谢,我在我的filedownloader函数中使用了带有@postconstruct的f:param调用,在它的定义中添加了一个void返回值,看起来效果不错
@ManagedProperty(value="#{param.filepath}")
private String filepath;
@PostConstruct
public void init() {
// do your initializations here
}