如果有人可以帮助我理解,当我们将SessionBean注入其中时ViewScoped bean的优势是什么呢会很棒.
我们还能节省会话内存的使用吗?
如果我们只使用SessionScoped bean或ViewScoped bean注入SessionBean,我相信会话内存占用没有区别.
当使用SessionScoped bean实现所有目标时,为什么我们要经历使用View和Session scoped bean的麻烦.
谢谢,Sundeep
非常感谢您帮助解决以下问题(JBoss 6.0,Mojarra - 2.2 Snapshot,facelet 1.1和PrimeFaces 3.0.M4:
问题是,在获取值集之前调用请求bean的post构造方法.我们如何确保首先设置会话bean上的参数值,然后调用请求bean的post构造方法.
问题#1:当点击"Next"时,这是一个ajax调用1. testRequestBB的"初始化"post构造方法被调用2. testSessionBB的"next"方法被调用来设置值
预期的行为应该是另一种方式,使用ajax调用在会话bean中设置值,然后应该初始化请求bean.
问题#2:请求bean的"初始化"后构造方法被调用两次.
- 是因为请求bean从基类扩展(尽管基类中没有post构造方法).
当显示test.xhtml页面时,可以采取哪些措施来解决获取post构造方法两次调用的问题?
这是代码:
<h:dataTable id="testId" emptyMessage="#{messages.noData}" var="test" value="#{testList}">
....
<f:facet name="footer">
<h:form id="pgId">
<h:commandLink value="#{messages.next} ">
<f:ajax listener="#{testSessionBB.next}" />
</h:commandLink>
.....
</h:form>
</f:facet>
</h:dataTable>
Run Code Online (Sandbox Code Playgroud)
@Named("testSessionBB")
@SessionScoped
public class TestSessionBB implements Serializable
{
private int testStartRow;
.....
public String next()
{
if (this.getTestStartRow() + 5 > 15) // hard coded value for simplicity in this post
{
this.setTestStartRow(15);
} else {
this.setTestStartRow(this.getTestStartRow() + 5);
} …Run Code Online (Sandbox Code Playgroud)