Google app engine SessionScoped Bean在Google Appengine上发帖时丢失数据
我使用Eclipse3.7GAE插件进行开发。我的应用程序使用JSF和数据存储,并根据进行了设置。在我的开发系统中,它运行良好。但是当部署到GAE时,SessionScoped Bean会在回发时丢失数据:Google app engine SessionScoped Bean在Google Appengine上发帖时丢失数据,google-app-engine,jsf-2,Google App Engine,Jsf 2,我使用Eclipse3.7GAE插件进行开发。我的应用程序使用JSF和数据存储,并根据进行了设置。在我的开发系统中,它运行良好。但是当部署到GAE时,SessionScoped Bean会在回发时丢失数据: // Input facelet <h:outputLabel for="popupCal">Date </h:outputLabel> <p:calendar value="#{editEntry.current.date1}" id="popupCal"
// 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";
}
...
//输入facelet
日期
代码
数量
@ManagedBean(name=“editEntry”)
@会议范围
公共类EditEntry扩展AbstractEntryBean实现可序列化{
@ManagedProperty(value=“#{sessionBean}”)
受保护的SessionBean SessionBean;
@ManagedProperty(value=“#{dao}”)
保护道道;
@施工后
公共void init(){
Logger.getLogger(getClass().getName()).log(Level.WARNING,“dao为null?{0}”,dao==null);
设置传输id(0L);
条目。清除();
setCurrent(新条目());
getCurrent().clear();
...
这个.refreshEntries();
}
公共条目(){
entries=dao.getEntries(current.getFinyr(),getTran_id());
Logger.getLogger(getClass().getName()).log(Level.INFO,“条目有{0}个条目”,entries.size());
}
公共字符串createCashExpression(){
if(dao==null){
Logger.getLogger(getClass().getName()).log(Level.WARNING,“dao为空”);
返回null;
}
条目。清除();
条目e=新条目();
e、 清除();
e、 setAccountCode(current.getAccountCode());
e、 setAccountName(dao.lookupAccountName(e.getAccountCode());
e、 setAmount(current.getAmount());
e、 setDate1(current.getDate1());
e、 setTran_id(getTran_id());
Key=dao.saveEntry(e,sessionBean.getFinyr());
e、 setId(key.getId());
条目。添加(e);
电流=e;
this.setTran_id(e.getTran_id());
Logger.getLogger(getClass().getName()).log(Level.INFO,“当前帐户为:{0}”,current.getAccountCode());
返回“newEntry?faces redirect=true”;
}
...
}
newEntry.xhtml
//editEntry.entries为空!
调用EditEntry.CreateCashExpression()时,日志显示EditEntry.current已正确填充并保存到数据存储中。数据存储查看器还显示数据。但在回发时,在newEntry.xhtml facelet中,editEntry.entries变为空,editEntry.current会丢失所有数据
我已经安装了ForceSessionSerializationPhaseListener,如日志中所述,显示调用了此侦听器
在web.xml中,javax.faces.PROJECT_阶段是生产阶段,我面临同样的问题,重定向后,上一个会话就不存在了。它仅在联机部署时发生 我认为这是由于javax.faces.STATE_SAVING_方法(在web.xml中)的会话变量设置为“client” 因此,在重定向之前,我需要显式设置会话,如下所示:
getSessionScope().put(sessionname,sessionObj);
public Map getSessionScope() {
return getFacesContext().getExternalContext().getSessionMap();
}
请调查会话cookie流量并报告结果。没有什么特别的。第一次访问时,我得到了JSESSIONID;使用gmail帐户登录后,我也得到了ACSID。在业务方法创建之前和之后,两个cookie的值和到期日期保持不变。
getSessionScope().put(sessionname,sessionObj);
public Map getSessionScope() {
return getFacesContext().getExternalContext().getSessionMap();
}