簡単な質問ですが、文字通り思い出せません。基本的に、Javaメソッドを特定の順序で実行したいのですが、完全に機能していましたが、最初に何かを追加する必要があり、順番に実行されません
基本的に以前はこのコードでしたが、
@PostConstruct
public void init() {
//System.out.println(destinationPDF);
//System.out.println(destination);
// Get the username from the login page, this is used to create a folder for each user
System.out.println("called get username");
username = FacesContext.getCurrentInstance().getExternalContext().getRemoteUser();
}
public void File() {
File theFile = new File(destination + username); // will create a sub folder for each user (currently does not work, below hopefully is a solution)
theFile.mkdirs();
System.out.println("Completed File");
}
実行され、次に必要なメソッドが自動的に呼び出され、次の順序で呼び出されます。
INFO: buttonToUploadText invoked
INFO: called get username
INFO: called handle file
INFO: Completed Creation of folder
INFO: Now in copying of file proccess
INFO: Completed Creation of folder for copy of PDF
INFO: End of copying file creation
INFO: Called CopyFile
INFO: New file created!
INFO: Copying is now happening
しかし、ファイルから変数を呼び出す新しいメソッドを追加しました:
@PostConstruct
public void loadProp() {
System.out.println("Loading properties");
InputStream in = this.getClass().getClassLoader().getResourceAsStream("config.properties"); //points to a properties file, this will load up destinations instead of having to declare them here
try {
configProp.load(in);
System.out.println(configProp.getProperty("destinationPDF"));
System.out.println(configProp.getProperty("destination"));
System.out.println(configProp.getProperty("fileList"));
} catch (IOException e) {
e.printStackTrace();
}
}
これは、変数を宣言するためにトリガーされたときに最初に実行する必要がありますが、完了したら public void int() を実行するようになりました。代わりに、多くをスキップして public void handleFileUpload を実行します
public void loadProp() から public void init() を呼び出す最良の方法は何ですか?
編集2:
private Properties configProp = new Properties();
public void loadProp() {
System.out.println("Loading properties");
InputStream in = this.getClass().getClassLoader().getResourceAsStream("config.properties"); //points to a properties file, this will load up destinations instead of having to declare them here
try {
configProp.load(in);
System.out.println(configProp.getProperty("destinationPDF"));
System.out.println(configProp.getProperty("destination"));
System.out.println(configProp.getProperty("fileList"));
} catch (IOException e) {
e.printStackTrace();
}
}
private String destinationPDF = configProp.getProperty("destinationPDF");
public String destination = configProp.getProperty("destination");
private String username;
//public static String destination = "D:/Documents/NetBeansProjects/printing~subversion/fileupload/uploaded/"; // main location for uploads//TORNADO ONLY //"D:/My Documents/NetBeansProjects/printing~subversion/fileupload/uploaded/"; // USE ON PREDATOR ONLY
public static String NewDestination;
public static String UploadedfileName;
public static String CompletefileName;
//
//Strings for file copy
//
//private String destinationPDF = "D:/Documents/NetBeansProjects/printing~subversion/fileupload/web/resources/pdf/"; //USE ON TORNADO//"D:/My Documents/NetBeansProjects/printing~subversion/fileupload/web/resources/pdf/";//USE ON PREDATOR
private String NewdestinationPDF;
public static String PdfLocationViewable;
//
@PostConstruct
public void init() {
FileUploadController.loadProp();
//System.out.println(destinationPDF);
//System.out.println(destination);
// Get the username from the login page, this is used to create a folder for each user
System.out.println("called get username");
username = FacesContext.getCurrentInstance().getExternalContext().getRemoteUser();
}