我正在尝试创建一个操作,其中服务器需要通过 GWTP 操作将对象的数组列表通过线路响应到客户端。
类别类
package com.business.share;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
public class Category implements Serializable{
Long id;
protected String name;
protected String description;
protected boolean status;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean getStatus() {
return status;
}
public void setStatus(boolean status) {
this.status = status;
}
}
GetCategories 类
package com.business.client.action;
import java.util.ArrayList;
import com.gwtplatform.dispatch.shared.ActionImpl;
import com.business.client.action.GetCategoriesResult;
import com.business.share.Category;
public class GetCategories extends ActionImpl<GetCategoriesResult> {
private ArrayList<Category> categories;
@SuppressWarnings("unused")
public GetCategories() {
// For serialization only
}
public GetCategories(ArrayList<Category> categories) {
this.categories = categories;
}
public ArrayList<Category> getCategories() {
return categories;
}
}
GetCategoriesResult 类
package com.business.client.action;
import java.util.ArrayList;
import com.gwtplatform.dispatch.shared.Result;
import com.business.share.Category;
public class GetCategoriesResult implements Result {
private ArrayList<Category> categories;
@SuppressWarnings("unused")
private GetCategoriesResult() {
// For serialization only
}
public GetCategoriesResult(ArrayList<Category> categories) {
this.categories = categories;
}
public ArrayList<Category> getCategories() {
return categories;
}
}
GetCategoriesActionHandler 类
package com.business.server.handler;
import java.util.ArrayList;
import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.business.client.action.GetCategories;
import com.business.client.action.GetCategoriesResult;
import com.business.share.Category;
import com.google.inject.Inject;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.Query;
import com.gwtplatform.dispatch.server.ExecutionContext;
import com.gwtplatform.dispatch.shared.ActionException;
public class GetCategoriesActionHandler implements
ActionHandler<GetCategories, GetCategoriesResult> {
@Inject
public GetCategoriesActionHandler() {
}
@Override
public GetCategoriesResult execute(GetCategories action,
ExecutionContext context) throws ActionException {
ArrayList<Category> categories = new ArrayList<Category>();
// dummy data
Category cat1 = new Category();
cat1.setName("cat1");
cat1.setDescription("cat1 desc");
cat1.setStatus(true);
Category cat2 = new Category();
cat1.setName("cat2");
cat1.setDescription("cat2 desc");
cat1.setStatus(false);
categories.add(cat1);
categories.add(cat2);
return new GetCategoriesResult(categories);
}
@Override
public void undo(GetCategories action, GetCategoriesResult result,
ExecutionContext context) throws ActionException {
}
@Override
public Class<GetCategories> getActionType() {
return GetCategories.class;
}
}
这是 CategoryPresenter 中的一段代码,它将异步发送到服务器。
@Override
protected void onReset() {
super.onReset();
GetCategories getCategoriesAction = new GetCategories();
dispatchAsync.execute(getCategoriesAction, getCategoriesCallback);
}
private final AsyncCallback<GetCategoriesResult> getCategoriesCallback =
new AsyncCallback<GetCategoriesResult>() {
@Override
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(GetCategoriesResult result) {
getView().getCategoryListBox().clear();
ArrayList<Category> categories = result.getCategories();
for(Category category : categories) {
getView().getCategoryListBox().addItem(category.getName());
}
}
};
我不知道这段代码有什么问题,但是 GWT 编译器总是给出这样的错误。
编译模块 com.business.Business 验证新编译的单元 在第一次通过时忽略了 3 个编译错误的单元。编译时使用 -strict 或将 -logLevel 设置为 TRACE 或 DEBUG 以查看所有错误。查找入口点类 [错误] 'file:/.blah..blah..blah../businessapp/src/com/business/client/presenter/CategoryPresenter.java' 中的错误 [错误] 第 75 行:没有源代码可用于 com.business.share.Category 类型;你忘了继承一个必需的模块吗?[错误] 'file:/.blah..blah..blah../businessapp/src/com/business/client/action/GetCategoriesResult.java' 中的错误 [错误] 第 11 行:没有可用于类型 com 的源代码.business.share.类别;你忘了继承一个必需的模块吗?[错误] 找不到类型“com.business.client.Business” [错误] 提示:以前的编译器错误可能导致此类型不可用 [错误] 提示:检查模块的继承链;它可能没有继承所需的模块,或者模块可能没有正确添加其源路径条目
在此错误消息之后,这意味着未找到 com.business.share.Category,但该文件已物理存储在该包中。我不明白为什么 GWT 找不到它。我注意到我在任何地方调用 Category 类,它总是会带来这个错误。有人知道发生了什么吗?
[编辑] 问题解决了。在我的 Business.gwt.xml 中,我有
<source path='shared'/>
但是我的共享包是 com.business.share(没有 d)我只是将包名称从共享重命名为共享。