start という名前ApplicationScopedのメソッドを持つ Beanを作成しました。開始メソッドでのPostConstructインスタンスを取得したいときはいつでも、それが返されます:FacesContextnull
@ManagedBean
@ApplicationScoped
public class RemoveOldFilesScheduler implements Serializable {
@PostConstruct
private void start() {
final FacesContext facesContext = FacesContext.getCurrentInstance();
if(facesContext != null) {
String realDownloadDirName = facesContext.getExternalContext().getRealPath("/") + DOWNLOAD_DIRECTORY;
File downloadDir = new File(realDownloadDirName);
if (downloadDir.exists()) {
removeOldFiles(downloadDir.listFiles());
}
}
}
facesContextこの状況でアクセスするにはどうすればよいですか?
start メソッドでダウンロード ディレクトリの実際のパスを取得したいのですが、を使用せずにディレクトリのパスを取得する方法がわかりませんFaceContext。
それを行う別の方法はありますか?