2016-02-25 60 views
4

I don't understand why this piece of code is working:<a jsf:rendered="#{...}"> is not interpreted as passthrough element

<h:link value="Login" rendered="#{sessionBean.userInSessionBean == null}" /> 

and this piece of code is not working:

<a jsf:rendered="#{sessionBean.userInSessionBean == null}">Login</a> 
+2

您錯過了以提供更多信息作爲您的命名空間定義,使用JSF版本,您正在測試它的瀏覽器... –

+0

@XtremeBiker這些東西都與它無關。 – EJP

+0

你是對的@XtremeBiker。我的JSF版本是2.2.12。我試過了Explorer,Chrome和Firefox。我也使用Prime Faces 5.3。 – Gavi

回答

7

A HTML element will only become a passthrough element if following conditions are met:

  1. There's at least one jsf:xxx attribute來自http://xmlns.jcp.org/jsf命名空間。
  2. 至少有一個與特定JSF組件關聯的「identifying attribute」。

對於<a>元件的識別屬性是必要的,這樣JSF可以決定是否它解釋爲<h:commandLink><h:outputLink><h:link>。如果沒有識別屬性,JSF將不知道您實際使用的組件是什麼,所以任何jsf:xxx屬性都將被忽略。 jsf:rendered不足以識別屬性,因爲它出現在每個單獨的JSF組件上,所以JSF仍然不知道您的意思。

鑑於您似乎打算有一個<h:link>,然後使用jsf:outcome作爲識別屬性。

<a jsf:outcome="login" jsf:rendered="#{empty sessionBean.userInSessionBean}">Login</a> 

一個完全不同的替代方案是包裹純HTML在<ui:fragment rendered>。另請參閱How to conditionally render plain HTML elements like <div>s?

相關問題