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 に答える