【发布时间】:2010-11-24 17:55:50
【问题描述】:
我会尽量用几行代码来解释我的问题:
template.xhtml - 这里我加载一个名为 get 参数的页面(例如 index.xhtml?page=homepage => 我加载 homepage.xhtml)
<h:panelGroup layout="block" id="content">
<c:catch>
<ui:include src="#{selector.page}.xhtml" />
</c:catch>
</h:panelGroup>
homepage.xhtml - 我自己的主页(无论是否登录都会改变)
<h:panelGroup rendered="#{!login.loggedIn}">
<h:outputLabel styleClass="content_title" value="im not logged" />
</h:panelGroup>
<h:panelGroup rendered="#{login.loggedIn}">
<h:outputLabel styleClass="content_title" value="im logged" />
</h:panelGroup>
ajax call - 这才是真正的问题;如果我这样打电话:
<f:ajax event="action" execute="param1 param2" render=":content"/>
selector bean:
package model;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean(name="selector")
@RequestScoped
public class Selector {
@ManagedProperty(value="#{param.page}")
private String page;
public String getPage() {
if(page.compareTo("")==0) {
this.page="homepage";
}
return page;
}
public void setPage(String page) {
this.page=page;
}
}
我将在模板上定义的 panelGroup content 上加载新数据。
问题是当我调用这个时,我丢失了page parameter(之前在选择器bean上设置的),我无法重新加载当前页面。
所以,你的诀窍是:
1 - 把 bean SessionScoped?
2 - 通过 ajax 调用获取值?
3 - 以其他方式定义我自己的应用程序?
任何建议将不胜感激:)
【问题讨论】: