I'm working on an ADF fusion application with JDeveloper that runs on a Weblogic Server 12c.
The application contains a JSF page that has amongst others a fileInput, a table and a button. After the user uploads a file, it gets parsed and the results are shown in the table as intended. The next step for the user is to click on a button to save the parsed results to the DB (via backing bean).
These are the mentioned elements in the JSF-document:
<af:inputFile label="file"
id="if1"
valueChangeListener="#{ResultMatching.valueChangeListener}"
binding="#{ResultMatching.bindingInputFileCSV}"/>
<af:button text="upload"
id="b1"
action="#{ResultMatching.readFile}"
binding="#{ResultMatching.bindingButtonReadFile}"/>
<af:table var="row"
rowBandingInterval="0"
id="t3"
value="#{ResultMatching.Results}"
binding="#{ResultMatching.bindingTableResults}"
fetchSize="32"
width="800"
partialTriggers="::b1 ::b21">
<!--column definitions-->
</af:table>
<af:button id="b21"
text="save"
action="#{ResultMatching.saveResults}"/>
These are the coherent methods in the backing bean ResultMatching.java
:
private ArrayList<Result> Results= new ArrayList<Result>();
private RichTable bindingTableResults;
public void readFile() {
Results.clear();
if (fileInputStream != null) {
for (HashMap<String, String> dataSet : FileHandler.parseCFFile(fileInputStream)) {
Result r = new Result("values from the dataSet");
Results.add(r);
}
matchResults();
} else {
String msg = "No file was selected for upload";
FacesContext.getCurrentInstance().addMessage(
null, new FacesMessage(FacesMessage.SEVERITY_INFO,msg, msg));
}
}
private void matchResults() {
//very complicated matching logic
bindingTableResults.setValue(Results);
AdfFacesContextImpl.getCurrentInstance().addPartialTarget(bindingTableResults);
System.out.println(Results.size()); //prints the correct amount of results like in the file
}
public void saveResults() {
if (Results.isEmpty()) {
System.out.println("Results is empty!");
return;
//here is where I end up
//i did no other GUI interaction meanwhile
//neither has the getter nor setter of Results been called
//why is it suddenly empty? Where are my objects???
}
for(Result r : Results){
//as Results is empty this loop always gets skipped
//and so does the actual update statement
}
}
The bean is view-scoped. Any ideas where my results went? Thank you in advance!
From your code, it looks like the ResultMatching bean is in request scope:
value="#{ResultMatching.Results}"
If you want to access the bean in view scope the EL should be
value="#{viewScope.ResultMatching.Results}"
You have to change the EL for every occurrence of ResultMatching in all EL. Make sure that the bean is defined in viewScope in your task flow.