2

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Evan Knowles
  • 7,426
  • 2
  • 37
  • 71

1 Answers1

8

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555