我是一个 JSF 2.0 新手,我正在尝试构建一个调度程序。到目前为止,在使用 primefaces 和 JSF 标记方面一切都进展顺利。但是我很难使用 p:schedule 标签。在列表中,我只希望日历(议程)显示在我的页面中,然后再继续下一部分并添加事件。我的问题是,这段代码不应该至少在我的页面中生成一些东西吗?
这是我的 scheduleBean.java
@ManagedBean(name="scheduler")
@ViewScoped
public class SchedulerBean extends PageCodeBase implements Serializable {
private static final long serialVersionUID = -1426310201082465397L;
private String loggedInUser;
private boolean authorizeduser=false;
private boolean showUnauthorizeduserMessage=true;
private String theme;
private AuthorizeduserManager AUM = (AuthorizeduserManager)getManagedBean("AuthorizeduserManager");
private ScheduleModel eventModel;
public void pageOnLoad(){
this.setLoggedInUser(getFacesContext().getExternalContext().getRemoteUser());
this.checkAuthorization();
this.retriveTheme();
this.eventModel = new DefaultScheduleModel();
}
private void checkAuthorization(){
ArrayList<Authorizeduser> athorizedUser= new ArrayList<Authorizeduser>();
athorizedUser.addAll(AUM.getAuthorizeduser());
for(Authorizeduser au:athorizedUser){
if (loggedInUser.equalsIgnoreCase(au.getEmail())){
setAuthorizeduser(true);
showUnauthorizeduserMessage = false;
return;
}
}
}//end checkAuthorization
private void retriveTheme(){
if(authorizeduser){
this.theme = AUM.findAuthorizeduserByEmail(loggedInUser).getThemepref();
}else{
this.theme = "blitzer";
}
}
private void persistTheme(String theme){
//System.out.println("persistTheme was called");
ArrayList<Authorizeduser> athorUser= new ArrayList<Authorizeduser>();
athorUser.addAll(AUM.getAuthorizeduser());
for(Authorizeduser au:athorUser){
if (loggedInUser.equalsIgnoreCase(au.getEmail())){
try {
au.setThemepref(theme);
AUM.updateAuthorizeduser(au);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
//Getters and setters
public String getLoggedInUser() {
return loggedInUser;
}
private void setLoggedInUser(String loggedInUser) {
this.loggedInUser = loggedInUser;
}
public boolean isAuthorizeduser() {
return authorizeduser;
}
private void setAuthorizeduser(boolean authorizeduser) {
this.authorizeduser = authorizeduser;
}
public boolean isshowUnauthorizeduserMessage() {
return showUnauthorizeduserMessage;
}
public void setshowUnauthorizeduserMessage(boolean showUnauthorizeduserMessage) {
this.showUnauthorizeduserMessage = showUnauthorizeduserMessage;
}
public String getTheme() {
return theme;
}
public void setTheme(String theme){
this.theme = theme;
this.persistTheme(theme);
}
public String logout() {
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
//System.out.println("logoutRequested");
return "logout";
}
public ScheduleModel getEventModel() {
return eventModel;
}
public void setEventModel(ScheduleModel eventModel) {
this.eventModel = eventModel;
}
}
这是我的 MasterLayout.xhtml
<f:view>
<!-- WelcomeBar -->
<div id="WelcomeBar">
<ui:include src="/resources/templates/WelcomeBar.xhtml"></ui:include>
</div>
<f:event listener="#{scheduler.pageOnLoad }" type="preRenderView"></f:event>
<h:form styleClass="form" id="form1" height="30">
<p:panel>
<div id="Header">
<ui:include src="/resources/templates/Header.xhtml"></ui:include>
</div>
<div id="content">
<ui:insert name="content"></ui:insert>
</div>
<div id="Footer">
<ui:include src="/resources/templates/Footer.xhtml"></ui:include>
</div>
</p:panel>
</h:form>
</f:view>
</h:body>
这是我的 schedule.xhtml,其中包含 p:schedule 标记:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
template="/resources/templates/MasterLayout.xhtml"
xmlns:p="http://primefaces.org/ui">
<!-- Content Properties -->
<ui:define name="content">
<p:schedule value="#{scheduler.eventModel}" widgetVar="myschedule">
</p:schedule>
</ui:define>
</ui:composition>
仅供参考,我创建了一个简单的页面 text.xhtml,它可以工作。所以它必须与我的模板方式有关:
<h:body>
<f:view>
<h:form styleClass="form" id="form1" height="30">
<p:panel>
<f:event listener="#{scheduler.pageOnLoad }" type="preRenderView"></f:event>
<h:outputText value="test"/>
<p:schedule value="#{scheduler.eventModel}" widgetVar="myschedule">
</p:schedule>
</p:panel>
</h:form>
</f:view>
</h:body>