eclipse-ee4j / mojarra

Mojarra, a Jakarta Faces implementation
Other
159 stars 109 forks source link

jsf:rendered inconsistently applied to html elements #5212

Closed codylerum closed 1 year ago

codylerum commented 1 year ago

The following works fine in JSF 2.3

<div jsf:rendered="#{false}">DIV is not rendered</diiv>

<div jsf:rendered="#{true}">DIV is rendered</diiv>

<p jsf:rendered="#{false}">p is not rendered</diiv>

<p jsf:rendered="#{true}">p is rendered</diiv>

<button type="button" jsf:rendered="#{false}">Does not render</button>

<button type="button" jsf:rendered="#{true}">Renders</button>

However if the element is an <a> then the jsf:rendered is not applied if the element does not have something like an jsf:outcome or jsf:action for example:

<a href="http://www.google.com" jsf:rendered="#{false}" target="_blank">Renders</a>

<a jsf:outcome="foo" href="http://www.google.com" jsf:rendered="#{false}" target="_blank">Does not render</a>

Expected behavior

Would expect that the jsf:rendered attribute is applied to any html element. It appears that the <a> element is being treated differently.

<button> which I would expect to be handle similarly as it also supports outcome and action, but is handled properly so this seems to only be an issue with the<a> element.

Environment JSF 2.3.17 Wildfly 26.0.1.Final

Additional context

I have not had a chance to test this on 4.0 as of yet.

BalusC commented 1 year ago

The <a> element indeed requires an additional "identifying attribute" because there are multiple components available for it and it's with solely rendered attribute not clear which one should be used. This is specified behavior. See also among others https://docs.oracle.com/javaee/7/tutorial/jsf-facelets009.htm#BABJADGH

I do however agree that it should at least default to a h:link with an empty outcome.

This is in turn not a Mojarra bug. This is a Faces feature. Move issue to https://github.com/jakartaee/faces/issues

codylerum commented 1 year ago

@BalusC Could it not be treated as a simple html element (same as a div) if there is no identifying attributes which would make it an h:commandLink or h:link?

Wondering if it should be treated as just a standard html element if it can't determine which it should be. I think that would be less surprising behavior rather than potentially having an <a> elemented rendered when it has a jsf:rendered="#{false}"

But maybe better discussed at https://github.com/jakartaee/faces/issues

codylerum commented 1 year ago

Created https://github.com/jakartaee/faces/issues/1790

BalusC commented 1 year ago

Could it not be treated as a simple html element (same as a div) if there is no identifying attributes which would make it an h:commandLink or h:link?

<a> cannot be an instance of UIPanel. Among others, that wouldn't allow you to modify the outcome (or even the action .. just saying).