我正在尝试创建一个操作,其中服务器需要通过GWTP Action通过线路响应对象的数组列表。
类别类
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.Category类型没有可用的源代码;你忘了继承一个必需的模块吗? [错误]无法找到'com.business.client.Business'类型 [错误]提示:以前的编译器错误可能导致此类型不可用 [错误]提示:检查模块中的继承链;它可能没有继承所需的模块,或者模块可能没有正确添加其源路径条目
发出此错误消息后,表示找不到com.business.share.Category,但此文件已经物理存储在该包中。我不明白为什么GWT找不到它。我注意到我在任何地方调用Category类,它总是带来这个错误。 有人知道发生了什么事吗?
[编辑] 问题已经解决了。 在我的Business.gwt.xml中,我有
<source path='shared'/>
但是我的共享包是com.business.share(没有d) 我只是将包名称从share重命名为shared。
答案 0 :(得分:0)
尝试将空构造函数添加到Category
类。