问题
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?
回答1:
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 :
- h:commandButton
回答2:
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
来源:https://stackoverflow.com/questions/20884950/what-is-the-difference-between-class-and-styleclass-attributes-in-jsf