如何通过GWTP操作通过导线传输对象的数组列表



我正在尝试创建一个操作,在该操作中,服务器需要通过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个单元。使用-restrict或-logLevel设置为TRACE或DEBUG进行编译以查看所有错误。查找入口点类[错误]'file:/.blah..blah./businessapp/src.com/business/client/presenter/CategoryPresenter.java'中存在错误[错误]第75行:类型com.business.share.Category没有可用的源代码;你忘了继承一个必需的模块吗?[错误]'file:/.blah..blah./businessapp/src.com/business/client/action/GetCategoriesResult.java'中存在错误[错误]第11行:类型com.business.share.Category没有可用的源代码;你忘了继承一个必需的模块吗?[错误]找不到类型"com.business.client.business"[ERROR]提示:以前的编译器错误可能使此类型不可用[错误]提示:检查模块的继承链;它可能没有继承所需的模块,或者模块可能没有正确地添加其源路径条目

此错误消息之后,意味着找不到com.business.share.Category,但此文件已物理存储在该包中。我不明白GWT为什么找不到它。我注意到,在我调用Category类的任何地方,它总是会带来这个错误。有人知道发生了什么?

[编辑]问题解决了。在我的Business.gwt.xml中,我有

<source path='shared'/>

但我的共享包是com.business.share(没有d)我只是将包名称从share重命名为shared。

尝试向Category类添加一个空构造函数。

相关内容

  • 没有找到相关文章

最新更新