【问题标题】:@viewScoped data bean survives after navigation to another pages (views) with Spring Web Flow and JSF-2@viewScoped 数据 bean 在使用 Spring Web Flow 和 JSF-2 导航到另一个页面(视图)后仍然存在
【发布时间】:2014-10-29 20:24:49
【问题描述】:

我正在使用 Spring Web Flow 和 JSF-2。

事实对我来说很奇怪,无法理解。

我有一个主页,一个典型的索引

我有 actionView 和一些过滤器(过滤将通过 ajax 调用进行)和一个用于根据过滤器信息显示结果的表格。

这个动作的后台bean被定义为@ViewScoped。 如果一开始我在过滤了一些数据后导航到索引,然后,我返回到我不希望找到显示的最后一个搜索的操作视图,我希望看到一个空视图,但过滤器不是空的并且数据结果被过滤。

为什么?如果我要定义 @ViewScope 是因为我希望在更改视图时必须删除后面的 bean 信息(在我的情况下 index 是另一个视图),但我一定是犯了一些错误。

这是我的代码:

我的父流程(简化):

<view-state id="index" view="../index.xhtml" redirect="true" popup="true"/>

<view-state id="action1Flow" view="flowRedirect:action1-flow" />

<global-transitions>
    <transition on="home" to="index" />
    <transition on="action1" to="action1Flow" />
</global-transitions>

action1-flow: (start-state="action1View")

<view-state id="action1View" view="../views/action1View.xhtml" redirect="true" popup="true"/>

action1View.xhtml:(简化,一个过滤器 -> 表格结果)

...
<p:panel id="filter" header="Filter example">
    <h:panelGrid columns="2">
        <h:outputLabel for="dataFilter" value="Filter"/>
        <p:inputText id="dataFilter" value="#{action1View.dataValue}"/>
            <p:ajax event="keyup" listener="#{action1View.filterData()}" update="table"/>
        </p:inputText>
    </h:panelGrid>
   </p:panel>

  <p:panel id="display" header="Data filtered">    
        <p:dataTable id="table" var="data" value="#{action1View.resultData"
         selection="#{action1View.selectedData}" rowKey="#{data.dataValue}"> 
        <p:column headerText="#{msg.id}" sortBy="#{data.dataValue}">
            <h:outputText value="#{data.dataValue}" />
        </p:column>      
    </p:dataTable>
</p:panel>
...
<p:commandButton value="Go to index" action="home"/>
...

action1View.java,后面的bean:

@ManagedBean
@ViewScoped
@Component("action1View")
public class Action1View implements Serializable {
    static final long serialVersionUID = 42L;
    List<ExampleBean> resultData = null;
    ExampleBean selectedData = null;
    Integer dataValue; 

    public ExampleBean getSelectedData() {
        return selectedData;
    }
    public void setSelectedData(ExampleBean selectedData) {
        this.selectedData = selectedData;
    }
    public Integer getDataValue() {
        return dataValue;
    }
    public void setDataValue(Integer dataValue) {
        this.dataValue = dataValue;
    }
    public void filterData() {
        // Some logic
        resultData = xxxxx;
    }
}

index.xhtml

...
<p:commandButton value="Go to index" action="action1"/>
...

对不起我的英语和...

您好!

【问题讨论】:

    标签: jsf-2 primefaces spring-webflow


    【解决方案1】:

    我找到了 GAP!

    我的 bean,除了 @ViewScoped 批注外,还使用此批注定义(如您在代码中所见):@Component("action1View") 没有明显原因。

    事实上,通过删除此注释,我让一切正常工作。

    我认为这是因为 Component 行为覆盖了 ViewScoped ,这样做只能为每个定义的类创建一个 bean,因此,信息保持及时(直到会话结束或应用程序关闭)。

    但如果有人能提供更多更丰富的信息,那就太好了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-12
      • 2010-11-03
      • 2011-02-16
      • 1970-01-01
      • 2014-06-21
      • 2012-04-27
      • 1970-01-01
      相关资源
      最近更新 更多