0

我有以下问题!

在我的一个网站上,我有一个按钮:

<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>

这是豆:

@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;
    }

因此,当我尝试使用此托管属性时,它会说:

表达式 #{SelectionBean.analyzerLog} 引用的对象的范围,视图,比会话的引用托管 bean (AnalyzerBean) 范围短,但正如您所见,两者都是 Session Scoped。可能是什么问题呢?

4

1 回答 1

0

如果您使用 JSF 2.x 并且想要浏览 Analyzerresult.xhtml 页面返回 analyzerresult

public String monitoringLog() throws FileNotFoundException, IOException{
  return "analyzerresult";
}

不需要 .xhtml 扩展名。

于 2013-07-02T13:52:56.333 回答