JSF-@ViewScope问题 [英] JSF - Problem with @ViewScope

查看:63
本文介绍了JSF-@ViewScope问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于登录状态(已记录,未记录),我有一个页面(在panelGroup中)加载两个不同的页面.这是主要的开关:

I have a page that load (in a panelGroup) two different page, due to the login status (logged, not logged). This is the main switch :

template.xhtml附言默认情况下,selector.page是主页"

template.xhtml P.S. selector.page is "homepage" as default

<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?

ProfileSelector is @ViewScope scoped. When i load the page and im logged, it initialize the ProfileSelector bean. Else, if i'm not logged and i do the login, it change the Content from homepage to profile, but the Bean is not initalized. So, how can i inizialize this bean when im not logged?

我认为上面的代码足以理解问题.

I think the code above is sufficent to understand the problem.

欢呼

推荐答案

  <c:catch>
                <ui:include src="/#{selector.page}/#{selector.page}.xhtml" />
            </c:catch>

问题是您正在使用破坏@ViewScope使用替代项的JSTL元素.

The problem is that you are using JSTL elements which break @ViewScope use alternative.

这篇关于JSF-@ViewScope问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆