J2JS
Home > Docs > Tips

1. Tips, Tricks and Troubleshooting

1. CSS Styling

To set the background color of an HTML element, use one of the following methods:

        CSSStyleDeclaration style = ((ElementCSSInlineStyle) element).getStyle();
        
        style.setProperty("backgroundColor", "red", null);
        ((CSS2Properties) style).setBackgroundColor("red");
        HTMLUtils.getStyle(element).setBackgroundColor("red");

Extracted from /projects/j2js-Runtime/test-src/Fragments.java
Only use if the style property is not known at compile time. Hence, the above usage in is discouraged.

Note: It is good practice to use CSS style sheets, possibly in conjunction with HTML class names, instead of setting style properties directly on individual elements.

1. Attribute removal

To remove a style attribute, set it to the empty string, not to null.

        CSS2Properties style = HTMLUtils.getStyle(element);
        style.setBorderTop("solid black");
        // Later ...
        style.setBorderTop("");

Extracted from /projects/j2js-Runtime/test-src/Fragments.java

2. URL Query Parameters

If the onLoad-method has a java.lang.String[] argument, then the values of the URL query parameters are passed through this argument.

The java.lang.System.getProperty(String key) method can also be used to access URL query parameters.

3. Trouble Shooting

1. Loaded page is dead

Is the correct assembly included within the <script/> tag? Is the correct static method specified as onLoad handler?

Last build on Sat Jan 03 11:06:48 CET 2009