我正在使用和JSF-2。
这一事实对我来说既奇怪又难以理解。
我有一个主页,一个典型的索引。
我和actionView都有一些过滤器(过滤将使用ajax调用进行)和根据过滤器信息显示结果的表。
此操作的后端被定义为@ViewScoped。如果首先在过滤一些数据之后导航到索引,然后返回到操作视图--我不希望找到显示的最后一个搜索--我希望有一个空视图,但是过滤器不是空的,数据结果被过滤了。
为什么?如果我定义@ViewScope的原因是,当我更改视图(在我的情况下,索引是另一个视图)时,我希望back bean信息必须被删除,但是我肯定犯了一些错误。
这是我的代码:
我的父流(简单化):
<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,的背豆:
@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"/>
...抱歉我的英语和..。
欢迎光临!
发布于 2014-10-29 12:24:49
我找到了缺口!
除了@ViewScoped注释之外,我的bean还使用这个注释定义(正如您在代码中看到的那样):@Component("action1View"),没有明显的原因。
事实上,通过删除这个注释,我让所有的东西都能正常工作。
我认为这是因为组件行为覆盖了ViewScoped 1,这样就只能为每个定义的类创建一个bean,因此信息会保持在时间上(直到会话结束或应用程序关闭为止)。
但如果有人能提供更多更丰富的信息,那就太好了。
https://stackoverflow.com/questions/26613842
复制相似问题