それぞれのファイルが見つからない場合にファイル ダウンロード リンクのクリックを処理するためのベスト プラクティスは何ですか?
特定の状況では、添付エンティティが DB に存在し、ファイル名のみを指し、ファイル ストレージ パスを個別/個別に構成できます。これはレガシー アプリ用であり、サポートする必要があります。
これは可能ですか?そのようなコードはどのように見えますか? 私は試した
if ( file.canRead() )
{
byte[] data = FileUtils.readFileToByteArray( file );
// goes to code like here: http://balusc.blogspot.de/2006/05/pdf-handling.html
downloadFile( attachment.getFileName(), data );
}
else
{
this.log.errorv( "Attachment {0} not found in configured storage path {1}", file, this.storagePath );
FacesContext facesContext = FacesContext.getCurrentInstance();
facesContext.addMessage( null,
new FacesMessage( FacesMessage.SEVERITY_ERROR, "Failed.",
"Downlosding file " + file + " failed! File doesn't exist in the configured storage path " + this.storagePath ) );
// ???
facesContext.responseComplete();
}
しかし、これは
XML-Verarbeitungsfehler: Kein Element gefunden
Adresse: https://localhost:8181/cmc-compliance/view/prototype/collisionManager.xhtml
Zeile Nr. 1, Spalte 1:
( <rant>
OMG、私は嫌いです...ええと、 int18nedエラーメッセージは嫌いです...誰かがこれが良い考えだと思った人を追い払う必要があります... )</rant>
OK、上記は「XML 処理エラー: 要素が見つかりません + 行 1、列 1」のようなものを意味します
私のコードは明らかに正しい方法ではありません...
データテーブルで JSF コードを使用しています。
<h:commandLink action="#{attachmentManager.downloadAttachment(att)}">
<h:graphicImage library="images/icons" name="page_white.png" />
<h:outputText value="#{att.fileName}" />
</h:commandLink>
私が理想的に望むのは、JSF メッセージ (または PrimeFaces のうなり声) を表示し、ページをそのままにしておくことです。つまり、同じページで完全な要求を再度発行する必要はありません。
これどうやってやるの?