Ich habe eine fileDownload-Komponente in einem DataTable, aber wenn ich es anklicke es scheint der FileDownloader wird aufgerufen, bevor die datlis.filepath Variable von setPropertyActionListener gesetzt wird.Cant instanziieren class- p: fileDownload aufgerufen vor f: setPropertyActionListener
Wenn ich auf Download klicke, bekomme ich "Kann instanziieren Klasse: ui.FileDownloader.com.sun.faces.mgbean.ManagedBeanCreationException: Cant instanziieren Klasse: ui.FileDownloader."
Mein JSF-Code ist:
<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>
Die Bohne, dass 'datlis' in meiner Anwendung ist ViewScoped darstellt - und ich habe überprüft, dass datlist.filepath nicht null ist. Und der Datei-Download-Bean (Filedownloader) ist wie folgt:
@ManagedBean(name="filedownloader")
@RequestScoped
public class FileDownloader {
private StreamedContent file;
public StreamedContent getFile() {
return file;
}
@ManagedProperty(value="#{param.filepath}")
private String filepath;
public String getFilepath() {
return filepath;
}
public void setFilepath(String filepath) {
System.out.println("> "+filepath);
this.filepath = filepath;
System.out.println(">> "+this.filepath);
}
public FileDownloader() throws FileNotFoundException {
System.out.println("100");
String filename = "/opt/glassfish3/glassfish/domains/domain1/datasets/string_compare/Business v2 Metadata/README.txt";
InputStream stream = new FileInputStream(filepath);
file = new DefaultStreamedContent(stream, "text/txt", "README.txt");
}
Der Stack-Trace erwähnt eine Nullpointer-Ausnahme in Bezug auf die Input und das ist, warum ich denke, die ‚filepath‘ Variable nicht gesetzt ist - und mein System Ausgabe zeigt nur die "100" von der System.out.println, und keine System-Ausgaben von der setFilepath-Funktion ... als ob es überhaupt nicht aufgerufen wird.
habe ich auch versucht:
<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>
mit dem zusätzlichen Code direkt über der filepath Getter/Setter in meiner Klasse Filedownloader:
@ManagedProperty(value="#{param.filepath}")
private String filepath;
Aber das scheint auch nicht zu funktionieren. Irgendwelche Ideen? Ich fühle, dass ich auf dem richtigen Weg bin, vielleicht nur die Elemente missbrauche ...
Dank habe ich den f: param Anruf mit @PostConstruct auf meiner Filedownloader Funktion übernehmen Sie eine Lücke Rückgabewert es Definition ist und es sieht aus wie es funktioniert – Alaph432