JSF-@ViewScope有问题
由于登录状态(已登录,未登录),我有一个页面(在panelGroup中)加载两个不同的页面。这是主开关:JSF-@ViewScope有问题,jsf,scope,jsf-2,javabeans,Jsf,Scope,Jsf 2,Javabeans,由于登录状态(已登录,未登录),我有一个页面(在panelGroup中)加载两个不同的页面。这是主开关: template.xhtmlp.S.selector.page默认为“homepage” <h:panelGroup layout="block" styleClass="contenitore"> <h:panelGroup layout="block"> <h:panelGroup layout="block" styleClass=
template.xhtml
p.S.selector.page默认为“homepage”
<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>
登录
<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>
ProfileSelector的作用域为@ViewScope。当我加载页面并记录im时,它初始化ProfileSelector bean。否则,如果我没有登录,并且我进行了登录,它会将内容从主页更改为概要文件,但Bean没有初始化。那么,当我没有登录时,我如何将这个bean序列化呢
我认为上面的代码足以理解这个问题
干杯
问题是,您使用的JSTL元素会破坏@ViewScope
使用alternative.类似的错误
那么我该如何解决这个问题呢?删除catch?问题是,如果用户添加另一个“页面”,可能会出现问题。我需要添加一种验证页面…尝试了。它不能解决我的问题。事实上,在我第一次登录时,我仍然需要点击我的按钮2次!
<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>
<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>
<c:catch>
<ui:include src="/#{selector.page}/#{selector.page}.xhtml" />
</c:catch>