我有以下问题!
在我的一个网站上,我有一个按钮:
<h:commandButton value="IDA Analyzer Results" action="#{SelectionBean.monitoringLog()}"/>
它调用bean的某些部分的方法:
@ManagedBean(name = "SelectionBean")
@SessionScoped
public class TableSelectionBean {
private List<String> analyzerLog = new ArrayList<String>();
public String monitoringLog() throws FileNotFoundException, IOException{
String fileName = "/opt/IDA2/Linux/bin/"+"filtered_"+selectionMonitoringData.get(0).getMonitoringName()+"_result.txt";
if(selectionMonitoringData.get(0).getIsExecuted())
{
BufferedReader br = new BufferedReader(new FileReader(fileName));
try {
String line;
while ((line=br.readLine()) != null) {
getAnalyzerLog().add(line);
}
} finally {
br.close();
System.out.println(getAnalyzerLog());
}
}
return "analyzerresult.xhtml";
}
点击此按钮后,您可以看到它导航到另一页:
<h:body>
<h:form>
<h:commandButton value="hi" action="#{AnalyzerBean.myMethod()}"></h:commandButton>
</h:form>
</h:body>
这是Bean:
@ManagedBean(name = "AnalyzerBean")
@SessionScoped
public class AnalyzerResultBean {
@ManagedProperty(value="#{SelectionBean.analyzerLog}")
private List<String> analyzerLog;
public void myMethod(){
System.out.print(analyzerLog);
}
/**
* @return the analyzerLog
*/
public List<String> getAnalyzerLog() {
return analyzerLog;
}
/**
* @param analyzerLog the analyzerLog to set
*/
public void setAnalyzerLog(List<String> analyzerLog) {
this.analyzerLog = analyzerLog;
}
因此,当我尝试使用此Managed属性时,它会说:
表达式#{SelectionBean.analyzerLog},view引用的对象的范围比引用的托管bean(AnalyzerBean)会话范围短,但是您可以看到两者都是Session Scoped。可能是什么问题?
答案 0 :(得分:0)
如果您使用JSF 2.x并且想要导航analyzeresult.xhtml页面返回analyzerresult
public String monitoringLog() throws FileNotFoundException, IOException{
return "analyzerresult";
}
.xhtml扩展名不需要。