Can I refer to listings in the context of the GWT UiBinder

I have an enumeration that looks like this

public enum MyEnum { A, B; } 

And then I have a UiBinder file with a custom component that has a setter and a receiver waiting for the listing above. (I removed the extra code for

 <ui:UiBinder ....> <g:HTMLPanel> .... <myNamespace:myComponent myAttribute="" /> .... </g:HTMLPanel> </ui:UiBinder> 

Can I refer to my enumeration and put this value in myAttribute? What I want to do is something like this

 <ui:UiBinder ....> <ui:with field="myEnumField" type="com.example.MyEnum" /> <g:HTMLPanel> .... <myNamespace:myComponent myAttribute="{myEnumField.A}" /> .... </g:HTMLPanel> </ui:UiBinder> 

However, it would seem that I cannot do this with ui: with. Can I do this at all?

+4
source share
2 answers

It is possible. You should be able to pass enum to the attribute directly, like,

 <ui:UiBinder ....> <g:HTMLPanel> .... <myNamespace:myComponent myAttribute="A" /> .... </g:HTMLPanel> </ui:UiBinder> 

The MyComponent widget must have a uiConstructor that accepts the MyEnum type.

 @UiConstructor public MyComponent(MyEnum myAttribute){ } 
+1
source

After searching a little more, I realized that you really can do the following:

 <ui:import field="com.example.MyEnum.*" /> <g:HTMLPanel> ... <myNamespace:myComponent myAttribute="{A}" /> ... </g:HTMLPanel> 
+8
source

All Articles