由于登录状态(已记录,未记录),我有一个页面加载(在panelGroup中)两个不同的页面。这是主要的开关:
template.xhtml
P.S。 selector.page是默认的“主页”
<h:panelGroup layout="block" styleClass="contenitore">
<h:panelGroup layout="block">
<h:panelGroup layout="block" styleClass="menu_table" id="login">
<ui:insert name="login_homepage" />
</h:panelGroup>
<h:panelGroup layout="block" id="content">
<c:catch>
<ui:include src="/#{selector.page}/#{selector.page}.xhtml" />
</c:catch>
</h:panelGroup>
</h:panelGroup>
</h:panelGroup>
homepage.xhtml
<h:panelGroup rendered="#{!user.loggedIn}">
<h:panelGroup layout="block" styleClass="content_title">
Homepage
</h:panelGroup>
</h:panelGroup>
<h:panelGroup rendered="#{user.loggedIn}">
<ui:include src="/profile/profile.xhtml" />
</h:panelGroup>
login
<ui:define name="login_homepage">
<h:form id="formLogin" prependId="false">
<h:inputHidden value="#{selector.page}" id="page" />
<h:panelGroup rendered="#{!user.loggedIn}">
<h:outputScript name="jsf.js" library="javax.faces" target="head" />
<h:outputLabel styleClass="menu_span" value="Username" />
<h:inputText value="#{user.nickname}" id="nickname" />
<h:outputLabel styleClass="menu_span" value="Password" />
<h:inputSecret value="#{user.password}" id="password" />
<h:outputLabel styleClass="menu_span">
<h:commandButton value="Login" action="#{user.checkLogin}">
<f:ajax event="action" execute="nickname password page" render=":login :content err"/>
</h:commandButton>
</h:outputLabel>
</h:panelGroup>
<h:panelGroup rendered="#{user.loggedIn}">
<h:outputLabel styleClass="menu_title" value="LOGGED" />
</h:panelGroup>
</h:form>
</ui:define>
profile.xhtml
<h:panelGroup layout="block" id="profileContent">
<h:form id="formProfile">
<h:outputScript name="jsf.js" library="javax.faces" target="head" />
<h:panelGroup rendered="#{profileSelector.profilePage=='main'}">
<ui:include src="/profile/profile_main.xhtml" />
</h:panelGroup>
<h:panelGroup rendered="#{profileSelector.profilePage=='edit' || profileSelector.profilePage=='editConfirm'}">
<ui:include src="/profile/profile_edit.xhtml" />
</h:panelGroup>
</h:form>
</h:panelGroup>
ProfileSelector是@ViewScope作用域。当我加载页面并记录时,它初始化ProfileSelector bean。否则,如果我没有登录并且我进行登录,它会将内容从主页更改为配置文件,但Bean不会被初始化。那么,当我没有记录时,我怎么能对这个bean进行初始化呢?
我认为上面的代码足以理解这个问题。
干杯
答案 0 :(得分:1)
答案 1 :(得分:0)
<c:catch>
<ui:include src="/#{selector.page}/#{selector.page}.xhtml" />
</c:catch>
问题是你正在使用JSTL元素,它会使@ViewScope
使用替代方法。