如何在实用程序类(GWT/GWTP)中使用接口MyCssResource?
我有 在TestView.java中如何在实用程序类(GWT/GWTP)中使用接口MyCssResource?,gwt,uibinder,gwtp,Gwt,Uibinder,Gwtp,我有 在TestView.java中 public interface MyResource extends ClientBundle{ @NotStrict @Source("/myResource.css") MyCssResource css(); } public interface MyCssResource extends CssResource { String gridEvenRow(); String gridOddRow();
public interface MyResource extends ClientBundle{
@NotStrict
@Source("/myResource.css")
MyCssResource css();
}
public interface MyCssResource extends CssResource {
String gridEvenRow();
String gridOddRow();
.... more styling here....
}
在TestPresenter.java中,我可以毫无问题地设置网格样式
@UiField MyResource res;
@Inject
public TestView(final Binder binder) {
widget = binder.createAndBindUi(this);
res.css().ensureInjected();
}
但是,它得到了运行时错误[error]-未捕获的异常转义了
?或者某种我不知道的错误
那么,如何在实用程序类(GWT/GWTP)中使用接口MyCssResource?我希望没有调用构造函数。您可以检查是否发出警报,并查看是否确保调用了resureinjected() 根据Java,静态方法调用不需要创建对象。所以不会创建实用程序对象,所以不会调用构造函数 对于GWT CssResources,必须确保在应用css之前调用Reinjected()
public class Utility {
public static MyResource res;
public Utility(){
res.css().ensureInjected();
}
public static void formatGridOddEvenRow(Grid grid){
for (int i = 1; i < grid.getRowCount(); i++) {
if((i%2) == 0){
grid.getRowFormatter().addStyleName(i, res.css().gridEvenRow());
}
else{
grid.getRowFormatter().addStyleName(i, res.css().gridOddRow());
}
}
}
}
将此代码添加到任意位置并使用它。如果您提供所有代码,可能会更有帮助 我把MyResource res=newmyresource();res.css().ensureInjected();在静态方法中&发现接口无法创建,所以可能是我们不知道如何使用接口
public class Utility {
public static MyResource res;
public Utility(){
res.css().ensureInjected();
}
public static void formatGridOddEvenRow(Grid grid){
for (int i = 1; i < grid.getRowCount(); i++) {
if((i%2) == 0){
grid.getRowFormatter().addStyleName(i, res.css().gridEvenRow());
}
else{
grid.getRowFormatter().addStyleName(i, res.css().gridOddRow());
}
}
}
}
public static final MyResource res=GWT.create(MyResource.class)
static{res.css().ensureInjected()}