0

我使用 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 已正确填充并保存到数据存储区。数据存储查看器也显示数据。但是在回发时,在 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,

4

1 回答 1

0

我面临同样的问题,重定向后,之前的会话消失了。它仅在在线部署时发生。

我认为这是由于 javax.faces.STATE_SAVING_METHOD 的会话变量设置为“客户端”(在 web.xml 中)

所以在重定向之前,我需要明确设置会话如下:

getSessionScope().put(sessionname,sessionObj);

public Map getSessionScope() {
  return getFacesContext().getExternalContext().getSessionMap();
}
于 2013-03-21T12:35:10.930 回答