<a jsf:rendered=“#{…}”> is not interpreted as passthrough element

梦想与她 提交于 2019-12-19 09:05:49

问题


I don't understand why this piece of code is working:

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

and this piece of code is not working:

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

回答1:


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

  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.

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.

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>

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?



来源:https://stackoverflow.com/questions/35637987/a-jsfrendered-is-not-interpreted-as-passthrough-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!