事情就是这样:我有一个管理用户门票的应用程序。 我有2个基本类:票证和用户。 使用GXT我有一些像这样的ColumnConfig类:
ColumnConfig<TicketProxy, String> dateColumn = new ColumnConfig<TicketProxy, String>(
new ValueProvider<TicketProxy, String>() {
public String getValue(TicketProxy object) {
Date initialDate = object.getInitialDate();
String date = "";
if (initialDate != null) {
date = dtFormat.format(initialDate);
}
return date;
}
public void setValue(TicketProxy object, String initialDate) {
if (object instanceof TicketProxy) {
object.setInitialDate(dtFormat.parse(initialDate));
}
}
public String getPath() {
return "initialDate";
}
}, 70, "Date");
columnsChamado.add(dateColumn);
但是我想从UserProxy类中获取一些数据,有些像这样:
ColumnConfig<UserProxy, String> userRoomColumn = new ColumnConfig<UserProxy, String>(
new ValueProvider<UserProxy, String>() {
public String getValue(UserProxy object) {
String userRoom = object.getUserRoom();
String room = "";
if (userRoom != null) {
room = userRoom;
}
return room;
}
public void setValue(UserProxy object, String userRoom) {
if (object instanceof UserProxy) {
object.setUserRoom(userRoom);
}
}
public String getPath() {
return "userRoom";
}
}, 70, "User's Room");
columnsChamado.add(userRoomColumn);
但GWT不允许我将“Proxy”参数更改为同一ColumnConfig中的另一个类。
如何在此ColumnConfig中从其他Proxy类获取数据?
我使用GXT 3.0(Sencha)+ Hibernate。
代理类: BaseEntityProxy:
package com.acme.ccc.shared;
import com.acme.ccc.server.locator.CCCLocator;
import com.acme.db.base.DatabaseObject;
import com.google.web.bindery.requestfactory.shared.EntityProxy;
import com.google.web.bindery.requestfactory.shared.ProxyFor;
import com.google.web.bindery.requestfactory.shared.SkipInterfaceValidation;
@SkipInterfaceValidation
@ProxyFor(value = DatabaseObject.class, locator = CCCLocator.class)
public interface BaseEntityProxy extends EntityProxy {
Long getId();
Long getVersion();
void setId(Long id);
void setVersion(Long version);
}
TicketProxy:
package com.acme.ccc.shared.entityproxy;
import java.util.Date;
import java.util.List;
import com.acme.ccc.db.Ticket;
import com.acme.ccc.server.locator.CCCLocator;
import com.acme.ccc.shared.BaseEntityProxy;
import com.google.web.bindery.requestfactory.shared.ProxyFor;
@ProxyFor(value = Ticket.class, locator = CCCLocator.class)
public interface TicketProxy extends BaseEntityProxy {
Date getPrazo();
void setPrazo(Date prazo);
TicketTipoProxy getTicketTipo();
void setTicketTipo(TicketTipoProxy chamadoTipo);
CanalOrigemProxy getCanalOrigem();
void setCanalOrigem(CanalOrigemProxy canalOrigem);
UserProxy getUser();
void setUser(UserProxy user);
CategoriaProxy getPedidoTipo();
void setPedidoTipo(CategoriaProxy pedidoTipo);
Date getInitialDate();
void setInitialDate(Date dt);
Long getTotal();
void setTotal(Long total);
}
的userProxy:
package com.acme.ccc.shared.entityproxy;
import java.util.List;
import com.acme.ccc.db.User;
import com.acme.ccc.server.locator.CCCLocator;
import com.acme.ccc.shared.BaseEntityProxy;
import com.google.web.bindery.requestfactory.shared.ProxyFor;
@ProxyFor(value = User.class, locator = CCCLocator.class)
public interface UserProxy extends BaseEntityProxy {
String getName();
String getUserRoom();
Long getTotal();
void setName(String name);
void setUserRoom(Sting room)
void setTotal(Long total);
}
答案 0 :(得分:0)
如果您有TicketProxy列,您可以从TicketProxy获取UserProxy吗?
ColumnConfig<TicketProxy, String> userRoomColumn = new ColumnConfig<TicketProxy, String>(
new ValueProvider<TicketProxy, String>() {
public String getValue(TicketProxy object) {
String userRoom = object.getUser().getUserRoom();
String room = "";
if (userRoom != null) {
room = userRoom;
}
return room;
}
public void setValue(TicketProxy object, String userRoom) {
object.getUser().setUserRoom(userRoom);
}
public String getPath() {
return "user.userRoom";
}
}, 70, "User's Room");
columnsChamado.add(userRoomColumn);
答案 1 :(得分:0)
gxt网格只能显示一种数据类型的数据。如果您放置一个TicketProxy行,您希望如何访问用户对象?
如果要独立显示故障单和用户(因此行是故障单或用户),则必须在网格中使用BaseEntityProxy:Grid<BaseEntityProxy>
。然后,您可以将列定义为ColumnConfig<BaseEntityProxy, ?>
并检查getter和setter中的类型:
List<ColumnConfig<BaseEntityProxy, ?>> columnsChamado = new ArrayList<ColumnConfig<BaseEntityProxy, ?>>();
ColumnConfig<BaseEntityProxy, String> dateColumn = new ColumnConfig<BaseEntityProxy, String>(
new ValueProvider<BaseEntityProxy, String>() {
private final DateTimeFormat dtFormat = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_FULL);
public String getValue(BaseEntityProxy object) {
Date initialDate = ((TicketProxy) object).getInitialDate();
String date = "";
if (initialDate != null) {
date = dtFormat.format(initialDate);
}
return date;
}
public void setValue(BaseEntityProxy object, String initialDate) {
if (object instanceof TicketProxy) {
((TicketProxy) object).setInitialDate(dtFormat.parse(initialDate));
}
}
public String getPath() {
return "initialDate";
}
}, 70, "Date");
columnsChamado.add(dateColumn);
ColumnConfig<BaseEntityProxy, String> userRoomColumn = new ColumnConfig<BaseEntityProxy, String>(
new ValueProvider<BaseEntityProxy, String>() {
public String getValue(BaseEntityProxy object) {
String userRoom = ((UserProxy)object).getUserRoom();
String room = "";
if (userRoom != null) {
room = userRoom;
}
return room;
}
public void setValue(BaseEntityProxy object, String userRoom) {
if (object instanceof UserProxy) {
((UserProxy)object).setUserRoom(userRoom);
}
}
public String getPath() {
return "userRoom";
}
}, 70, "User's Room");
columnsChamado.add(userRoomColumn);
ColumnModel<BaseEntityProxy> cm = new ColumnModel<BaseEntityProxy>(columnsChamado);
另一方面,如果您希望一个网格行显示用户和票证,则必须使用包装类:
class TicketWithUserProxy extends BaseEntityProxy{
private UserProxy userProxy;
private TicketProxy ticketProxy;
public UserProxy getUserProxy() {
return userProxy;
}
public void setUserProxy(UserProxy userProxy) {
this.userProxy = userProxy;
}
public TicketProxy getTicketProxy() {
return ticketProxy;
}
public void setTicketProxy(TicketProxy ticketProxy) {
this.ticketProxy = ticketProxy;
}
}
并相应地设置您的网格(Grid<TicketWithUserProxy>
):
List<ColumnConfig<TicketWithUserProxy, ?>> columnsChamado = new ArrayList<ColumnConfig<TicketWithUserProxy, ?>>();
ColumnConfig<TicketWithUserProxy, String> dateColumn = new ColumnConfig<TicketWithUserProxy, String>(
new ValueProvider<TicketWithUserProxy, String>() {
private final DateTimeFormat dtFormat = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_FULL);
public String getValue(TicketWithUserProxy object) {
Date initialDate = object.getTicketProxy().getInitialDate();
String date = "";
if (initialDate != null) {
date = dtFormat.format(initialDate);
}
return date;
}
public void setValue(TicketWithUserProxy object, String initialDate) {
object.getTicketProxy().setInitialDate(dtFormat.parse(initialDate));
}
public String getPath() {
return "initialDate";
}
}, 70, "Date");
columnsChamado.add(dateColumn);
ColumnConfig<TicketWithUserProxy, String> userRoomColumn = new ColumnConfig<TicketWithUserProxy, String>(
new ValueProvider<TicketWithUserProxy, String>() {
public String getValue(TicketWithUserProxy object) {
String userRoom = object.getUserProxy().getUserRoom();
String room = "";
if (userRoom != null) {
room = userRoom;
}
return room;
}
public void setValue(TicketWithUserProxy object, String userRoom) {
object.getUserProxy().setUserRoom(userRoom);
}
public String getPath() {
return "userRoom";
}
}, 70, "User's Room");
columnsChamado.add(userRoomColumn);
ColumnModel<TicketWithUserProxy> cm = new ColumnModel<TicketWithUserProxy>(columnsChamado);