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>
そして、次のページである found.xhtml の縮小バージョンを次に示します。
<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>
両方の xhtml ページは、同じマネージド Bean を使用します。index.xhtml の CommandButton をクリックすると、Finder Bean (現在は ViewScoped) も使用する found.xhtml ページに移動します。問題は、Finder Bean を SessionScoped にしない限り、Finder Bean が #{finder.name} (ユーザーがインデックス ページに入力し、見つかったページに渡す必要がある) を取得しないことです。
したがって、SessionScoped にすると、問題は、man ページでの新しい検索時に、found.xhtml ページが見つかったページに同じ値を表示し続けることです。データベース内の値が変更されたにもかかわらず、同じ値。私の理解では、ViewScoped にすると、表示される値を更新するために、ページが読み込まれるたびに新しいクエリが実行されます。しかし、これを行う方法がわかりません。
@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";
}
誰にもアイデアがありますか?