我正在从接缝2.2(jsf 1.2,jboss6)迁移到接缝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标签不适用于接缝2.3?
答案 0 :(得分:1)
此问题的解决方案是关闭部分状态保存。只需将其添加到web.xml:
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>false</param-value>
</context-param>