Gwt 带小部件的UIBinder

Gwt 带小部件的UIBinder,gwt,widget,uibinder,Gwt,Widget,Uibinder,我正试图使用UIBinder向面板添加一个小部件,但该组合无法加载,以下是我的xml: <ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder' xmlns:g='urn:import:com.google.gwt.user.client.ui' xmlns:my='urn:import:com.abc.client.test.ui'> <g:HTMLPanel ui:field="mai

我正试图使用UIBinder向面板添加一个小部件,但该组合无法加载,以下是我的xml:

<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
         xmlns:g='urn:import:com.google.gwt.user.client.ui'
         xmlns:my='urn:import:com.abc.client.test.ui'>
 <g:HTMLPanel ui:field="mainLayoutPanel">

  <g:SimplePanel ui:field="menuPanel" >
    <my:MainMenuViewImpl ui:field="mainMenu"/>
  </g:SimplePanel>

  <!-- the widget causing the issue -->
  <my:FinancialsNav ui:field="nav"/>

  <g:SimplePanel ui:field="mainPanel" />

 </g:HTMLPanel>
</ui:UiBinder>

FinancialsNav
小部件具有带参数的构造函数。所以不要创建参数构造函数

条目
等于
newfinancialsnav()

在大多数情况下,这意味着它们必须是默认可实例化的;也就是说,它们必须提供零参数构造函数。你必须通过辩论

 /** Used by MyUiBinder to instantiate FinancialsNav */
  @UiFactory FinancialsNav makeFinancialsNav() { // method name is insignificant. do start with make
    return new FinancialsNav(eventBus);
  }
提及


你能显示客户端工厂代码吗

好的,我发现了错误,实际上与UIBinder没有直接关系

在实现UIBinder的同时,我试图减少我的应用程序中面板使用的表的数量

当我注意到披露面板是基于一个表格时,我删除了我在FinancialNav中的一个中间垂直面板。 因此,具有DisclosurePanel-->按钮,而不是DisclosurePanel-->垂直面板-->按钮。这会导致整个块不显示


@阿德诺耶尔和@bumika:谢谢你的帮助

我试过了,但没有效果。我认为UIField(provided=true)负责告诉UIBinder这个字段接受参数(如图所示:)不,他将nav设置为“provided=true”,所以他的FinancialNAV是用他放在构造函数中的行初始化的:clientFactory.getNav()你能试着在你的FinancialNav构造函数上设置@Inject吗?我还希望看到clientFactory的代码。我没有使用GIN/GUICE,因此@Inject会触发一个错误。通过使用@UiField(provided=true)添加客户机工厂代码no将提供新的实例化对象。它不负责说出论点。正如@adenoyelle告诉我的,我还想看看clientFactory代码。另请参阅如何在构造函数中传递参数的答案!!
public class FinancialsNav extends Composite implements ClickHandler{

private VerticalPanel nav=new VerticalPanel();
// Operations
private DisclosurePanel operationsWrapper=new DisclosurePanel(Proto2.constants.financials_navigation_operations());
private NavButton product=new NavButton(Proto2.constants.financials_navigation_products(),
        SharedUtilities.PRODUCT_TOKEN);


private NavButton generalOptions=new NavButton(Proto2.constants.financials_navigation_generalOptions(),"");

private ArrayList<NavButton[]> buttons;
private NavButton[] operationsButtons={product,vc,fc,emp,others};
//...
private NavButton[] optionsButtons={generalOptions};

private final EventBus bus;

public FinancialsNav(EventBus bus){
    this.bus=bus;
    buildNav();
    initWidget(nav);
}

private void buildNav(){
    buttons=new ArrayList<NavButton[]>();
    buttons.add(operationsButtons);
    //...
    buttons.add(optionsButtons);

    int n=buttons.size();
    int nn;
    for(int i=0;i<n;i++){
        nn=buttons.get(i).length;
        for(int j=0;j<nn;j++){
            (buttons.get(i)[j]).addClickHandler(this);
            (buttons.get(i)[j]).setStylePrimaryName(NAV_BUTTON_STYLE);
            if(i==0){
                operationsWrapper.add(buttons.get(i)[j]);
            //...
            }else if(i==4){
                optionsWrapper.add(buttons.get(i)[j]);
            }
        }
    }

    nav.add(operationsWrapper);
    // ...
    nav.add(optionsWrapper);

}
public class ClientFactoryImpl implements ClientFactory{
private static final EventBus eventBus=new SimpleEventBus();
private static final PlaceController placeController=new PlaceController(eventBus);

private static final CreatePlanServiceAsync createPlanService=GWT.create(CreatePlanService.class);

private static final FinancialsNav navView=new FinancialsNav(eventBus);
private static final MainMenuViewImpl mainMenuView=new MainMenuViewImpl();

@Override
public EventBus getEventBus(){
    return eventBus;
}

@Override
public PlaceController getPlaceController(){
    return placeController;
}

@Override
public FinancialsNav getNav(){
    return navView;
}

@Override
public MainMenuViewImpl getMainMenuView(){
    return mainMenuView;
}

@Override
public CreatePlanServiceAsync getCreatePlanService(){
    return createPlanService;
} 
}
 /** Used by MyUiBinder to instantiate FinancialsNav */
  @UiFactory FinancialsNav makeFinancialsNav() { // method name is insignificant. do start with make
    return new FinancialsNav(eventBus);
  }