我使用Eclipse 3.7 GAE插件进行开发。我的应用程序使用JSF和数据存储区,并按照https://sites.google.com/a/wildstartech.com/adventures-in-java/Java-Platform-Enterprise-Edition/JavaServer-Faces/javaserver-faces-20/configuring-javaserver-faces-20-to-run-on-the-google-appengine进行设置。在我的开发系统中,它运行良好。但是当部署到GAE时,SessionScoped Bean会在回发后丢失数据:
// Input facelet
<h:outputLabel for="popupCal">Date </h:outputLabel>
<p:calendar value="#{editEntry.current.date1}" id="popupCal" />
<h:outputLabel for="code">Code </h:outputLabel>
<h:inputText id="code" value="#{editEntry.current.accountCode}"/>
<h:outputLabel for="amt">Amount </h:outputLabel>
<h:inputText id="amt" value="#{editEntry.current.amountInDollars}"/>
<h:commandButton action="#{editEntry.createCashExpenditure}" value="Create Entry"/>
@ManagedBean(name="editEntry")
@SessionScoped
public class EditEntry extends AbstractEntryBean implements Serializable {
@ManagedProperty(value="#{sessionBean}")
protected SessionBean sessionBean;
@ManagedProperty(value="#{dao}")
protected Dao dao;
@PostConstruct
public void init() {
Logger.getLogger(getClass().getName()).log(Level.WARNING, "dao is null? {0}", dao==null);
setTran_id(0L);
entries.clear();
setCurrent(new Entry());
getCurrent().clear();
...
this.refreshEntries();
}
public void refreshEntries() {
entries = dao.getEntries(current.getFinyr(), getTran_id());
Logger.getLogger(getClass().getName()).log(Level.INFO, "entries has {0} items", entries.size());
}
public String createCashExpenditure() {
if (dao == null) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, "dao is null");
return null;
}
entries.clear();
Entry e = new Entry();
e.clear();
e.setAccountCode(current.getAccountCode());
e.setAccountName(dao.lookupAccoutName(e.getAccountCode()));
e.setAmount(current.getAmount());
e.setDate1(current.getDate1());
e.setTran_id(getTran_id());
Key key = dao.saveEntry(e, sessionBean.getFinyr());
e.setId(key.getId());
entries.add(e);
current = e;
this.setTran_id(e.getTran_id());
Logger.getLogger(getClass().getName()).log(Level.INFO, "current account is: {0}", current.getAccountCode());
return "newEntry?faces-redirect=true";
}
...
}
newEntry.xhtml
<p:dataTable id="items" value="#{editEntry.entries}" var="item">
// editEntry.entries is EMPTY!
当调用EditEntry.createCashExpenditure()时,日志显示EditEntry.current已正确填充,并保存到数据存储区。数据存储区查看器还显示数据。但是在post-back上,在newEntry.xhtml facelet中,editEntry.entries变为空,EditEntry.current丢失所有数据。
我已经按照http://java.zacheusz.eu/google-app-engine-http-session-vs-jsf-en/394/中的提法设置了ForceSessionSerializationPhaseListener。日志显示了这个侦听器被调用。
在web.xml中,javax.faces.PROJECT_STAGE是Production,
答案 0 :(得分:0)
我面临同样的问题,重定向后,前一个会话消失了。它只在部署在线时发生。
我认为这是因为javax.faces.STATE_SAVING_METHOD(在web.xml中)将会话变量设置为'client'
所以在重定向之前,我需要显式设置会话如下:
getSessionScope().put(sessionname,sessionObj);
public Map getSessionScope() {
return getFacesContext().getExternalContext().getSessionMap();
}