很难找到有关GWTP(GWT平台)的问题。如何在GWT平台中将参数传递给UiBinder的构造器视图(通过使用setInSlot)?
好的,这是我的故事。我正在使用GWTP & eclipse自动创建Presenter-View结构。
实施例中,我创建在eclipse一个TestPresenter,&它创建的3个文件:TestPresenter.java,TestView.java,TestView.xml
在TestView.xml,我有:
<g:RadioButton ui:field="firstRadioButton" value="false" text="1st" />
<g:RadioButton ui:field="secondRadioButton" value="false" text="2nd" />
<g:RadioButton ui:field="bothRadioButton" value="true" text="Both" />
现在我想每个TestView自动设置组名,所以在TestView.java
public class TestView extends ViewImpl implements
TestPresenter.MyView {
private final Widget widget;
@UiField RadioButton firstRadioButton;
@UiField RadioButton secondRadioButton;
@UiField RadioButton bothRadioButton;
private String groupName;
@UiFactory
RadioButton makeRadioButton() {
return new RadioButton(groupName);
}
public interface Binder extends UiBinder<Widget, TestView> {
}
@Inject
public TestView(final Binder binder) {
widget = binder.createAndBindUi(this);
}
@Override
public Widget asWidget() {
return widget;
}
public RadioButton getFirstRadioButton() {
return firstRadioButton;
}
public RadioButton getSecondRadioButton() {
return secondRadioButton;
}
public RadioButton getBothRadioButton() {
return bothRadioButton;
}
}
在TestPresenter.java,
public class TestPresenter extends
PresenterWidget<TestPresenter.MyView> {
public interface MyView extends View {
public RadioButton getFirstRadioButton();
public RadioButton getSecondRadioButton();
public RadioButton getBothRadioButton();
}
}
好,最后我想在MainPresenter.java
使用许多TestPresenter(通过使用setInLot)所以,在MainPresenter.java,我有:
public static final Object SLOT1=new Object();
public static final Object SLOT2=new Object();
public static final Object SLOT3=new Object();
public static final Object SLOT4=new Object();
//...... more lot
@Inject TestPresenter testPresenter1;
@Inject TestPresenter testPresenter2;
@Inject TestPresenter testPresenter3;
@Inject TestPresenter testPresenter4;
//.. more test presenter
在MainView.java
,我已经setInSlot
@UiField HTMLPanel mainHtmlPanel;
@Override
public void setInSlot(Object slot, Widget content){
if(slot==MainPresenter.SLOT1){
mainHtmlPanel.clear();
if(content!=null){
mainHtmlPanel.add(content);
}
}
else if(slot==MainPresenter.SLOT2){
mainHtmlPanel.clear();
if(content!=null){
mainHtmlPanel.add(content);
}
}
//... more else if here
}
现在,如果我只是做这样的话,我不能单独通过组名每个TestPresenter &那不好。所以我想为每个TestPresenter传递groupName字符串,以便每个都有自己的groupName。这样的东西
@Inject TestPresenter testPresenter1 ("group1");
@Inject TestPresenter testPresenter2 ("group2");
@Inject TestPresenter testPresenter3 ("group3");
@Inject TestPresenter testPresenter4 ("group4");
...
但我不知道如何正确,所以请告诉我如何正确地在GWTP?
工厂是,如果你需要的参数主持人的路要走。 +1 – spg
嗨亚历克西斯,谢谢,无论如何,我没有测试你的解决方案,但你的想法“setGroupName”触发我的思想,所以我可以调整我的代码升技,它工作正常。看到我的回答者 – Tum