Jsf ManagedBean不断返回相同的查询结果(会话/视图范围?)

Jsf ManagedBean不断返回相同的查询结果(会话/视图范围?),jsf,jsf-2,Jsf,Jsf 2,我在index.xhtml页面中有以下内容 <h:form id="findForm"> <h:panelGrid columns="2" cellpadding="5"> <p:outputLabel value="Name" for="name"/> <p:inputText id="name" value="#{finder.name}"/>

我在index.xhtml页面中有以下内容

<h:form id="findForm">
        <h:panelGrid columns="2" cellpadding="5">                
            <p:outputLabel value="Name" for="name"/>
            <p:inputText id="name" value="#{finder.name}"/>

            <f:facet name="footer">
                <p:commandButton value="Find"
                action="#{finder.gotoFoundPage}"/>
            </f:facet>
        </h:panelGrid>
</h:form>

有人有想法吗?

请记住,每当您使用
?faces redirect=true
技巧时,用户的浏览器将使用HTTP GET请求重定向,这将导致JSF清除视图中存储的任何状态。 因此,即使您使用
@ViewScoped
bean,在重定向之后,您也会得到一个全新的实例


在您的情况下,由于这是一个简单的搜索,如果数据对URL中的显示不敏感,您可能希望使用视图参数进行搜索。查看更多关于这方面的信息以及与在JSF bean和页面之间传递数据相关的其他信息。

听起来我们不在同一页面上,但几乎在同一页面上。它当前是ViewScope,重定向后我不会得到一个全新的实例,因此没有干净的状态。相反,每次我从索引页面输入搜索文本时,它都会将我重定向到找到的页面,但在我已经用新数据更新了数据库字段之后,数据仍然是旧的。明天早上我会去看风景参数。谢谢。你也可以回发到同一个视图,并有条件地呈现结果。@Ender好吧,当你使用会话作用域时,你会得到旧数据,但这是很有经验的。因此,会话范围可能不是您想要的。正如上面的评论所说,另一个好的选择是将搜索表单和结果放在同一个页面中,并有条件地呈现它们。如果你不需要把搜索表单放在每个页面上,那可能是一个很好的尝试。
    <p:dataTable id="myTable" var="item" 
        value="#{finder.byName}" rowKey="#{item.name}" 
        paginator="true" rows="20" 
        selection="#{finder.selectedItem}" selectionMode="single">

        <p:column headerText="Name" sortBy="#{item.name}"
                filterBy="#{item.name}" id="name">
            #{item.name}
        </p:column>
    </p:dataTable>
@EJBs({@EJB(name="ejb/MyBean1", beanInterface=IMyBean1.class),
       @EJB(name="ejb/MyBean2", beanInterface=IMyBean2.class)})
@ManagedBean(name="finder")
@ViewScoped
public class Finder implements Serializable {

    // ...

    public String gotoFoundPage() {
        return "found?faces-redirect=true";
    }