[英]JSF2 with GAE and ViewScoped ManagedBean
在本教程之后,我設法使用JSF2獲得了Googles AppEngine的工作原型。 現在我對ViewScoped ManagedBean有一些奇怪的行為:
@ManagedBean @ViewScoped
public class TestBean implements Serializable
{
private String text; //getter/setter
private List<String> texts; //getter
@PostConstruct public void init()
{
texts = new ArrayList<String>();
texts.add("Test");
text = new String();
}
public void save(ActionEvent ae)
{
texts.add(text);
text = new String();
}
}
這是我的.xhtml頁面:
<h:body id="body">
<f:view contentType="text/html">
<h:form id="frm">
<p:panel>
<h:panelGrid columns="2" id="grid">
<p:inputText value="#{testBean.text}"/>
<p:commandButton value="Add" update=":frm:op @parent"
actionListener="#{testBean.save}" />
</h:panelGrid>
</p:panel>
<p:outputPanel id="op">
<p:dataTable var="v" value="#{testBean.texts}">
<p:column><h:outputText value="#{v}" /></p:column>
</p:dataTable>
</p:outputPanel>
</h:form>
</f:view>
</h:body>
這適用於本地部署(使用GAE的Eclipse工具),但如果我將其部署到GAE,如果單擊Add -Button則沒有任何反應。 使用范圍(GAE)的其他測試在單擊“ 添加”后顯示以下內容:
@RequestScoped
:輸入的文本不會消失,也不會添加到dataTable中 @ViewScoped
:輸入的文本不會消失,也不會添加到dataTable @SessionScoped
:輸入的文本消失,dataTable總是有兩個條目:“Test”和最后輸入的Text 我從教程中得到了相同的設置
<context-param> //web.xml
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
//appengine-web.xml
<sessions-enabled>true</sessions-enabled>
更新1
以下是使用@ManagedBean @ViewScoped
注釋的其他測試的結果:
在第一次請求(或手動刷新頁面)期間,調用@PostConstruct init()
方法。 如果我點擊按鈕沒有發生任何事情 , test.jsf
的請求會記錄在app engine日志中,但我的save()
方法中沒有日志。 Firebug向我展示了對test.jsf
的POST請求和以下答案:
<?xml version='1.0' encoding='UTF-8'?>
<partial-response><error>
<error-name>class javax.faces.application.ViewExpiredException</error-name>
<error-message>
<![CDATA[viewId:/test.jsf - View /test.jsf could not be restored.]]>
</error-message>
</error>
<extension primefacesCallbackParam="validationFailed">
{"validationFailed":false}
</extension>
</partial-response>
更新2
我使用過mojarra-2.0.4但現在更新到2.0.6。 同樣的問題,但一個新的觀察:如果我清除所有Firefox緩存, ViewExpiredException
沒有出現,但我只能將1個元素添加到List<String>
。 @PostConstruct
僅調用一次,而不是每次單擊按鈕。
然后我嘗試了myfaces-2.0.7,但得到了這個例外:
Uncaught exception from servlet
java.lang.NoClassDefFoundError: Could not initialize class
com.google.apphosting.runtime.security.shared.stub.javax.naming.InitialContext
我不確定我是否應該試着讓myfaces工作,因為谷歌在他們的教程中明確提到了mojarra(2.0.4)。
參考
通常我不回答我的問題,我只是將這個答案評為解決方法,而不是正確的答案。 事件,如果我不喜歡客戶端狀態保存,這似乎修復了奇怪的行為。 但我必須詳細檢查這個:
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
也許我們應該等到JAVASERVERFACES-1886得到解決。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.