25

I see, that in JSF most of the standard components that mapped to HTML tags, e.g. <h:commandButton/>, have attributes class and styleClass. But no matter, which one I use, both is rendered as class attributes in markup.

So why there are two attributes with the same purpose?

east825
  • 909
  • 1
  • 8
  • 20

2 Answers2

23

There is simply no class attribute in JSF components.

From the doc, attribute styleClass :

Space-separated list of CSS style class(es) to be applied when this element is rendered. This value must be passed through as the "class" attribute on generated markup.

The styleClass is simply converted as class in the rendered HTML.

More info :

Alexandre Lavoie
  • 8,711
  • 3
  • 31
  • 72
  • Oh, you're right. My bad. I was experimenting with [HTML5 Friendly Markup](http://docs.oracle.com/javaee/7/tutorial/doc/jsf-facelets009.htm) in JSF and for some reason start thinking that plain JSF components has `class` attribute as well. Thanks for the link to documentation. – east825 Jan 02 '14 at 15:33
3

See this references:

http://www.roseindia.net/jsf/commandButton.shtml

http://www.developersbook.com/jsf/jsf-tags-reference/html/commandButton.php

style: If you want ot add any CSS with the component then you can put the style as the value of the attribute. Added CSS will be applied on for the component.

styleClass: This attribute holds the CSS class name which is defined in the external style sheet.

The attribute style in JSF is equivalent to attribute style in HTML.

The attribute styleClass in JSF is equivalent to attribute class in HTML.

Regards

Matthias
  • 143
  • 1
  • 8
esmoreno
  • 658
  • 5
  • 12