2010-11-29 8 views
0

Ich habe eine Seite, die aufgrund des Login-Status (in einer panelGroup) zwei verschiedene Seiten geladen (geloggt, nicht geloggt). Dies ist der Hauptschalter:JSF - Problem mit @ViewScope

template.xhtml P.S. selector.page ist "Startseite" als Standard

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

Profil Der Selektor ist auf @ViewScope beschränkt. Wenn ich die Seite lade und die Im-Datei lade, initialisiert sie die Bean ProfileSelector. Sonst, wenn ich nicht angemeldet bin und die Anmeldung mache, ändere ich den Inhalt von der Startseite zum Profil, aber die Bean wird nicht initialisiert. Also, wie kann ich diese Bean initialisieren, wenn ich nicht angemeldet bin?

Ich denke, der obige Code ist ausreichend, um das Problem zu verstehen.

Prost

Antwort

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

Das Problem ist, dass Sie JSTL Elemente verwenden, die @ViewScope bedienbare Alternative zu brechen.

+0

So, wie ich dieses Problem beheben? Fang entfernen? – markzzz

+0

Ja. Es funktioniert nicht mit JSF2 ViewScope – Dejell

+0

Problem ist, dass, wenn der Benutzer eine andere "Seite" hinzufügen könnte ein Problem sein. Ich muss eine Art Validierungsseite hinzufügen ... – markzzz