Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using class attribute instead of styleClass of a JSF component actually works, why?

As far as I understood, we needed to use styleClass= as the JSF components don't support using just class=.

I've noticed recently that some components that were using class= were still rendering correctly. As a minimal example,

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html">

    <h:head>
        <title>Simple JSF Facelets page</title>
    </h:head>

    <h:body>
       <h:inputText class="wut" anothertag="hi" value="me"/>
    </h:body>

</html>

This produces

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <link type="text/css" rel="stylesheet" href="/individuallifefaz/javax.faces.resource/theme.css.xhtml?ln=primefaces-aristo"/>
        <title>Simple JSF Facelets page</title></head>
    <body>
        <input type="text" name="j_idt5" value="me" class="wut"/>
    </body>

</html>

Why is this working? It's clearly not just passing through any unknown tags, as the anothertag is stripped out.

like image 674
Evan Knowles Avatar asked Dec 04 '25 13:12

Evan Knowles


1 Answers

This is actually done by the view technology Facelets, not by the JSF component itself. Facelets has an alias for class attribute which automatically maps to styleClass. This was implemented as part of support for jsfc attribute as used in "designer friendly Facelets" which should make things like this possible:

<input type="text" jsfc="h:inputText" class="foo" />

If you use JSF with a different view technology (although so far there's none which is a serious alternative to Facelets, and JSP is deprecated), then there's no guarantee that <h:inputText class> would work.

See also:

  • Is there a way to run a JSF page without building the whole project?
like image 56
BalusC Avatar answered Dec 07 '25 04:12

BalusC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!