我正在尝试使用 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>
对应的java类:
public class AppLayoutImpl extends Composite implements AppLayout{
@UiField
HTMLPanel mainLayoutPanel;
interface AppLayoutUiBinder extends UiBinder<Widget,AppLayoutImpl>{}
private static AppLayoutUiBinder binder=GWT.create(AppLayoutUiBinder.class);
@UiField
SimplePanel menuPanel;// nav at the top
@UiField(provided=true)
FinancialsNav nav;// nav on the side
@UiField
SimplePanel mainPanel;// center
@UiField(provided=true)
MainMenuViewImpl mainMenu;
public AppLayoutImpl(ClientFactory clientFactory){
mainMenu=clientFactory.getMainMenuView();
nav=clientFactory.getNav();
initWidget(binder.createAndBindUi(this));
}
@Override
public Widget asWidget(){
return this;
}
}
导致问题的小部件:
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);
}
FinancialsNav 小部件在不与 UIBinder 一起使用时工作正常,而 AppLayout 的其余部分在 FinancialsNav 不存在时按预期工作。
我花了几个小时查看各种教程和示例,但根本找不到代码有什么问题。我还尝试了各种解决方法,例如在 UIBinder 中声明一个面板而不是 FinancialsNav 并将导航添加到面板中。
而且所有东西都在同一个包中,所以它不应该是一个导入问题。
任何帮助将非常感激...
这是客户端工厂
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;
}
}