在seam 2.3中使用jstl标签而不长时间运行会话是行不通的



我正在从seam 2.2 (jsf 1.2、jbosss6)迁移到seam 2.3 (jsf 2、jboss 7),发现了一些奇怪的行为。我可以用联系人列表示例复制它:

编辑viewContact.xhtml页面并替换以下片段:

<h3>
  <h:outputText id="Comments" value="Comments" rendered="#{not empty contact.comments}" />
  <h:outputText id="noComments" value="No Comments" rendered="#{empty contact.comments}" />
</h3>

,像这样:

<c:if test="#{not empty contact.comments}">
  <h3><h:outputText value="Comments" /></h3>
</c:if>
<c:if test="#{empty contact.comments}">
  <h3><h:outputText value="No Comments" /></h3>
</c:if>

(不要忘记添加命名空间xmlns:c="http://java.sun.com/jsp/jstl/core")

我知道改变是没有意义的——它只会显示我的问题。

重建/重新部署后,当您转到viewContact页面并尝试添加任何新评论时,您将得到:

请求处理异常:

Caused by javax.servlet.ServletException with message: "java.lang.IllegalStateException: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: org.jboss.seam.example.contactlist.Comment.contact -> org.jboss.seam.example.contactlist.Contact"

现在让我们做一些其他的改变,在进入viewContact页面后开始长时间运行的对话(并在持久化评论后结束对话)

在pages.xml中插入以下片段:

<page view-id="/viewContact.xhtml">
    <begin-conversation />
    <param name="contactId" value="#{contactHome.id}" converterId="javax.faces.Long" />
    <navigation>
        <rule if-outcome="persisted">
            <end-conversation />
            <redirect />
        </rule>
        <rule if-outcome="removed">
            <redirect view-id="/search.xhtml" />
        </rule>
    </navigation>
</page>

在viewContact.xhtml中更改提交按钮:

<h:commandLink id="submit" action="#{commentHome.persist}" value="Create Comment" >
  <s:conversationId/>
</h:commandLink>

现在,在重新部署之后,可以添加新的注释-不会抛出异常。

有人能向我解释为什么使用jstl标签没有长时间运行的对话不工作与seam 2.3?

此问题的解决方案是关闭部分状态保存。把这个添加到web.xml:

<context-param>
    <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
    <param-value>false</param-value>
</context-param>

相关内容

最新更新