< a jsf:rendered ="#{...}>不解释为直通元素 [英] <a jsf:rendered="#{...}"> is not interpreted as passthrough element
问题描述
我不明白为什么这段代码起作用:
I don't understand why this piece of code is working:
<h:link value="Login" rendered="#{sessionBean.userInSessionBean == null}" />
这段代码不起作用:
<a jsf:rendered="#{sessionBean.userInSessionBean == null}">Login</a>
推荐答案
只有满足以下条件,HTML元素才会成为直通元素:
A HTML element will only become a passthrough element if following conditions are met:
- There's at least one
jsf:xxx
attribute fromhttp://xmlns.jcp.org/jsf
namespace. - There's at least one "identifying attribute" associated with a specific JSF component.
对于<a>
元素,标识属性是必需的,因此JSF可以决定将其解释为<h:commandLink>
,<h:outputLink>
还是<h:link>
.如果没有可识别的属性,JSF将不知道您实际上打算使用什么组件,因此任何jsf:xxx
属性都将被忽略. jsf:rendered
不足以作为标识属性,因为它出现在每个JSF组件上,因此JSF仍然不知道您的意思是什么.
For the <a>
element an identifying attribute is necessary so JSF can decide whether to interpret it as <h:commandLink>
, <h:outputLink>
or <h:link>
. Without an identifying attribute, JSF wouldn't have any idea what component you actually meant to use, so any jsf:xxx
attributes will be ignored. The jsf:rendered
is not sufficient as identifying attribute because it appears on every single JSF component, so JSF would still have no idea which one you meant.
鉴于您似乎打算使用<h:link>
,然后使用jsf:outcome
作为标识属性.
Given that you seem to intend to have a <h:link>
, then use jsf:outcome
as identifying attribute.
<a jsf:outcome="login" jsf:rendered="#{empty sessionBean.userInSessionBean}">Login</a>
一种完全不同的替代方法是将纯HTML包装在<ui:fragment rendered>
中.另请参见如何有条件地呈现纯HTML元素,例如< div> s?
A completely different alternative is to wrap plain HTML in an <ui:fragment rendered>
. See also How to conditionally render plain HTML elements like <div>s?
这篇关于< a jsf:rendered ="#{...}>不解释为直通元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!