Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between style and styleClass in jsf page

Tags:

html

css

jsf-2

I have started working with a java code base where style and styleClass keywords are used to style the different elements in the jsf page. The project is using jsf 2.2.

The 'style' keyword is used to apply html attributes like:

<h:panelGroup style="margin-top:60px">
</h:panelGroup>

where as 'styleClass' keyword is used to apply the classes/styles from the .css file like:

<h:panelGroup layout="block" styleClass="panel panel-default">    
</h:panelGroup>

So my question is, is there a rule for which keyword is used where or is it just a matter of choice in this case? From this link I don't understand any difference between the two keywords.

like image 283
rehas Avatar asked Feb 14 '17 16:02

rehas


People also ask

What is styleClass?

The style and styleClass attributes allow you to specify Cascading Style Sheets (CSS) styles for the rendered output of your tags.

What is the difference between JSF style and HTML style?

The attribute style in JSF is equivalent to attribute style in HTML. The attribute styleClass in JSF is equivalent to attribute class in HTML. Thanks for contributing an answer to Stack Overflow!

What is the difference between style and styleclass?

These attributes allow you to use your own styles and style classes to control the look and feel of the resulting HTML. style allows you to set styles directly on a component, while styleClass lets you attach classes for styles defined elsewhere. For example, the following code sets the class of the <apex:outputText > and applies a style.

What is the use of styleclass attribute in HTML?

The styleClass is simply converted as class in the rendered HTML. Show activity on this post. 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.

When to use style and when to use JavaScript?

The latter should only be used if classes “can’t handle it”. For example, style is acceptable if we calculate coordinates of an element dynamically and want to set them from JavaScript, like this: For other cases, like making the text red, adding a background icon – describe that in CSS and then add the class (JavaScript can do that).


Video Answer


1 Answers

Both attributes are used to define style properties for the component. The styleClass attaches css classes to the component while the style attribute is used to define inline style properties that will be applied to the single element.

this:

<h:panelGroup style="margin-top:60px">
</h:panelGroup>

would generate the following HTML:

<span style="margin-top: 60px"></span>

Note that it is a span HTML element because the panelGroup renders a span by default.

while

<h:panelGroup layout="block" styleClass="panel panel-default">    
</h:panelGroup>

would generate:

<div class="panel panel-default"></div>

This is basic HTML knowledge anyway has not much to do with JSF except for the naming (i.e. style and styleClass)

like image 176
500 Server error Avatar answered Oct 09 '22 03:10

500 Server error