PDA

View Full Version : [FIXED] Component.removeStyleName(...) doesn't works for not rendered component



Alex.Leshkin
22 Aug 2008, 4:19 AM
Detailed description of the problem
If a Component instance is not rendered, then removeStyleName do nothing.

GXT version
1.0.2

Host mode / web mode / both
both

Browser and version
IE, FF

Operating System
Windows XP Home SP2

Sample code
This sample first appends x-item-disabled style name, then removes this style.
After rendering field looks like disabled.



public class TestCase extends ContentPanel implements EntryPoint {

public TestCase() {
final TextField<String> field = new TextField<String>();
field.addStyleName("x-item-disabled");
field.removeStyleName("x-item-disabled");
this.add(field);
}

public void onModuleLoad() {
final Viewport viewport = new Viewport();
viewport.setLayout(new FitLayout());
viewport.add(this);
RootPanel.get().add(viewport);
}

}
Suggestion
I think style is not removed because removeStyleName method has no affect for not rendered component:

com.extjs.gxt.ui.client.widget.Component.removeStyleName(String) source code for 1.0.2:


public void removeStyleName(String style) {
if (rendered) {
fly(getStyleElement()).removeStyleName(style);
} else if (style != null) {
String[] s = style.split(" ");
style = "";
for (int i = 0; i < s.length; i++) {
if (!s[i].equals(style)) {
style += " " + s[i];
}
}
}
}
This method should looks like:


public void removeStyleName(String style) {
if (rendered) {
fly(getStyleElement()).removeStyleName(style);
} else if (style != null && cls != null) {
String[] s = cls.split(" ");
cls = "";
for (int i = 0; i < s.length; i++) {
if (!s[i].equals(style)) {
cls += " " + s[i];
}
}
}
}

darrellmeyer
22 Aug 2008, 1:09 PM
This has previously been fixed in SVN. Thanks.

Alex.Leshkin
10 Sep 2008, 11:50 PM
It is desirable to check cls field not null value and avoid NPE for not rendered component w/o style:

Something like:


if (rendered) {
....
} else if (style != null && cls != null) {
....
}