Skip to content

5. How to create custom css property

Web Firm Framework edited this page Aug 19, 2017 · 2 revisions

You can use com.webfirmframework.wffweb.csswff.CustomCssProperty class to create a custom css property. See the below samples.

Sample1 :

Div div = new Div(null, new Style(new CustomCssProperty("new-property-name", "new-property-value")));
System.out.println(div.toHtmlString(true));

Sample2 :

Style style = new Style();
CustomCssProperty newCssProperty = new CustomCssProperty("new-property-name", "new-property-value");
style.addCssProperty(newCssProperty);
Div div = new Div(null, style);
System.out.println(div.toHtmlString(true));

// cssProperty will be the same object newCssProperty
CssProperty cssProperty = style.getCssProperty("new-property-name");

Sample3 :

Style style = new Style();
style.addCssProperty("new-property-name", "new-property-value");
Div div = new Div(null, style);
System.out.println(div.toHtmlString(true));

// cssProperty will be an instance of CustomCssProperty
CssProperty cssProperty = style.getCssProperty("new-property-name");

Here the Sample1, Sample2 and Sample3 code will print the same result :

<div style="new-property-name: new-property-value;"></div>

OR

You can create create your own css property class by extending CustomCssProperty class given as below

import com.webfirmframework.wffweb.csswff.CustomCssProperty;

public class VibrateCssProperty extends CustomCssProperty {

    public VibrateCssProperty(String cssValue) {
        super("vibrate", cssValue);
    }

    // TODO add needful feature methods for this css property

}
public static void main(String[] args) {

    Div div = new Div(null, new Style(new VibrateCssProperty("yes"), BoxSizing.CONTENT_BOX)) {
        Div div = new Div(this, new Id("55555Id"));
    };

    System.out.println(div.toHtmlString(true));
}

it will print as

<div style="vibrate: yes; box-sizing: content-box;">
    <div id="55555Id"></div>
</div>