laaglu / lib-gwt-svg

a general purpose SVG library for GWT. The goal is to make it easy to do SVG graphics in a GWT application
http://www.vectomatic.org/libs/lib-gwt-svg
39 stars 23 forks source link

Can't use style properties on SVGImage in UiBinder #15

Open jcairney opened 9 years ago

jcairney commented 9 years ago

I'm using lib-gwt-svg 0.5.10 with GWT-2.7.0, and found that when I tried:

<svg:SVGImage ui:field="popoutButton" resource="{my.resourceBundle.mySVGresource}" />

it works fine, but as soon as I try to add style name attributes, I see a null pointer exception when instantiating the UiBinder implementation class due to 'element' var not being set in the UiObject super class of SVGImage (I think. Each debugging method and browser I tested gave me a null pointer assertion or exception in different but related classes in the library). The failing markup looked like this:

<svg:SVGImage ui:field="popoutButton" resource="{my.resourceBundle.mySVGresource}" classNameBaseVal="{style.popoutBtn}"/>

or this:

<svg:SVGImage ui:field="popoutButton" resource="{my.resourceBundle.mySVGresource}" styleName="{style.popoutBtn}"/>

The workaround was to leave the classNameBaseVal attribute there, but set the resource at the java level by calling the SVGResource contructor of SVGImage, and setting @UiField(provided = true) on the popoutButton field.

laaglu commented 9 years ago

Hi, This problem seems similar to the one for which I recently received a pull request. I propose to merge the discussion of in this issue thead.

I have not been able to reproduce the probem. Here is what I have attempted. Using a recent build stack (Apache Maven 3.2.3, openjdk version "1.8.0_40", gwt-2.7.0, lib-gwt-svg-0.5.11-SNAPSHOT), I tried to modify the widgets part of lib-gwt-svg-samples in the following way.

Line https://github.com/laaglu/lib-gwt-svg-samples/blob/master/src/main/resources/org/vectomatic/svg/samples/client/widgets/WidgetsSample.ui.xml: 193

<svgui:SVGImage ui:field="hearts" resource="{resources.hearts}" classNameBaseVal="{style.hearts}"/>

is changed to:

<svgui:SVGImage ui:field="hearts" resource="{resources.hearts}" classNameBaseVal="{style.hearts}" width="355px"/>

I then rebuilt the code, and looked at the code generated by GWT/UiBinder for this part, in target/gen/org/vectomatic/svg/samples/client/widgets/WidgetsSample_WidgetsSampleBinderImpl.java. Here is the relevant excerpt for the generated code

private org.vectomatic.dom.svg.ui.SVGImage build_hearts() {
// Creation section.
final org.vectomatic.dom.svg.ui.SVGImage hearts = (org.vectomatic.dom.svg.ui.SVGImage) GWT.create(org.vectomatic.dom.svg.ui.SVGImage.class);
// Setup section.
hearts.setResource(get_resources().hearts());
hearts.setClassNameBaseVal("" + get_style().hearts() + "");
hearts.setWidth("355px");
...
return hearts;
}

As can be seen, the resource is clearly set immediately after the constructor is called, which seems in accordance to what is done by the org.vectomatic.dev.svg.impl.gen.SVGImageParser in lib-gwt-svg. NPE cannot occur in this context.

Can you provide more details on the issue or a test case to reproduce ?

marian486 commented 9 years ago

Hello, I have same problem ! without styleName working properly but after set styleName I get always exception ....

Caused by: com.google.gwt.core.client.JavaScriptException: (TypeError) : Cannot set property 'className' of undefined at Unknown.$setClassName(sm.embedded.smbar.SmbarWidgetset-0.js) at Unknown.setStyleName(sm.embedded.smbar.SmbarWidgetset-0.js) at Unknown.setStyleName_1(sm.embedded.smbar.SmbarWidgetset-0.js) at Unknown.build_imguser(sm.embedded.smbar.SmbarWidgetset-0.js) at Unknown.get_imguser(sm.embedded.smbar.SmbarWidgetset-0.js) at Unknown.build_f_HTMLPanel1(sm.embedded.smbar.SmbarWidgetset-0.js) at Unknown.get_f_HTMLPanel1(sm.embedded.smbar.SmbarWidgetset-0.js) at Unknown.createAndBindUi_4(sm.embedded.smbar.SmbarWidgetset-0.js) at Unknown.createAndBindUi_3(sm.embedded.smbar.SmbarWidgetset-0.js) at Unknown.NoRegisterDialogUi(sm.embedded.smbar.SmbarWidgetset-0.js)

marian486 commented 9 years ago

I see i have version 0.5.10 ! how i can download lib-gwt-svg-0.5.11-SNAPSHOT ?