< a jsf:rendered ="#{...}>不解释为直通元素 [英] <a jsf:rendered="#{...}"> is not interpreted as passthrough element

查看:240
本文介绍了< a jsf:rendered ="#{...}>不解释为直通元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白为什么这段代码起作用:

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:

  1. 至少有一个 jsf:xxx属性http://xmlns.jcp.org/jsf名称空间开始.
  2. 至少有一个"识别属性 与特定的JSF组件关联.
  1. There's at least one jsf:xxx attribute from http://xmlns.jcp.org/jsf namespace.
  2. 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?

这篇关于&lt; a jsf:rendered =&quot;#{...}&gt;不解释为直通元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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