我想一個小部件添加到使用UiBinder的,但複合材料根本不加載面板,這裏是我的xml:UiBinder的與窗口小部件
<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;
}
}
而且Widget的導致了問題:
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,並將nav添加到面板。
另外一切都在同一個包中,所以它不應該是一個導入問題。
任何幫助,將不勝感激......
這裏是clientFactory
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;
}
}
我試過沒有效果。 我認爲UIField(provided = true)負責告訴UIBinder該字段需要參數(如下所示:https://developers.google.com/web-toolkit/doc/2.4/DevGuideUiBinder#Lazy) – user2177336 2013-05-14 09:09:24
不,他把導航設置爲「provided = true」,所以他的FinancialsNav使用他在構造函數中放置的行進行初始化:clientFactory.getNav() – 2013-05-14 09:35:14
您可以嘗試將@Inject放在您的FinancialsNav構造函數上嗎?我也很高興看到clientFactory的代碼。 – 2013-05-14 09:42:57