Search code examples
gwtgwt2uibinder

Can I use enum values as field values inside UiBinder template?


Can I use enum values as field values inside UiBinder template ? I'm using GWT 2.4

Something like this

<ui:with field="en" type="com.mine.courierApp.shared.PayerType" />

looks promising, where

public enum PayerType
{
    Sender,
    Recipient
}

but I can't refer to values of the enum by en.Sender.

Is it even possible ?


Solution

  • <ui:import field='com.mine.courierApp.shared.PayerType.Sender' />
    

    or

    <ui:import field='com.mine.courierApp.shared.PayerType.*' />
    

    And then you can use it as payerType='{Sender}'.

    But UiBinder should automatically try to translate enum constant names into values, so the following should work without any need for a ui:with:

    <my:MyWidget payerType='Sender' />
    

    If the MyWidget widget has a public void setPayerType(PayerType type) method, UiBinder should look for an enum value named Sender (from the *.ui.xml file) in the PayerType enum (from the method's argument type).