【问题标题】:Managed property between SessionScoped ManagedBeansSessionScoped ManagedBeans 之间的托管属性
【发布时间】:2013-07-02 13:45:29
【问题描述】:

我有以下问题!

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

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

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

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

【问题讨论】:

    标签: jsf jakarta-ee


    【解决方案1】:

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

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

    .xhtml 扩展名不需要。

    【讨论】:

    • 是的,但这不是问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-03
    • 2011-06-18
    • 1970-01-01
    • 2011-09-04
    • 2011-06-20
    • 1970-01-01
    • 2015-08-29
    相关资源
    最近更新 更多