簡體   English   中英

richfaces 4 + jsf和faces-config.xml無法正常工作

[英]richfaces 4+jsf and faces-config.xml that doesn't work

我使用richfaces4。而且我有具有屬性-用戶的會話bean。 我希望如果用戶為null,則我的xhtml頁不會呈現請求,因為我有帶有if-tag的faces-config.xml(請參見下文)。 但是它們呈現(僅當我鍵入url myComp:8080 / JSF / faces / clients.xhtml時),並且在調試器中看到未在會話bean中檢查用戶屬性。

faces-config.xml

<navigation-rule>
  <from-view-id>/login.xhtml</from-view-id>
      <navigation-case>
       <from-outcome>clients</from-outcome>
       <if>#{userBean.isUser}</if>
       <to-view-id>/clients.xhtml</to-view-id>
      </navigation-case>

我需要一些VeiwHandler還是faces-config.xml出現問題?

好吧,顯然這是行不通的,因為您實際上沒有從/login.xhtml導航到/clients.xhtml對嗎? 對於要評估的導航規則,你需要實際是對login.xhtml ,然后通過該網頁上的控件導航clients.xhtml

導航案例涵蓋特定的導航案例,即if-then-else邏輯。 因此,直接進入結果將完全忽略導航邏輯。 這就是為什么最好在目的地實施驗證。 <f:event name="preRenderView"/>的基礎上,如下所示在clients.xhtml上嘗試以下操作:

  1. 將以下內容添加到您的clients.xhtml 它規定了一個方法checkValidUser

     <f:metadata> <f:event type="preRenderView" listener="#{myBean.checkValidUser}"> </f:metadata> 
  2. 在您的支持bean中,添加以下內容

     @ManagedProperty("#{userBean}") UserBean theUserBean; //this injects the UserBean into the destination bean. I'm assuming UserBean is a SessionScoped bean here public void checkValidUser(){ if(userBean.isUser==false){ throw new ValidationException("not a valid user"); } } 

另外,您可以只將@PostConstruct批注添加到checkValidUser並完全忽略(1)。 它將實現基本相同的效果, checkValidUser將在實例化bean之后立即運行。 基於faces-config.xml的導航方法,IMO具有隱含的缺陷和樂觀的態度,因為如您所見,繞過和破壞您的應用程序太容易了

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM