GWT Autobean Bean 为空
Posted
技术标签:
【中文标题】GWT Autobean Bean 为空【英文标题】:GWT Autobean Bean is null 【发布时间】:2017-02-09 11:57:02 【问题描述】:请帮帮我,我做错了什么
InfraNameModel
public interface InfraNameModel
String getInfraName();
void setInfraName(String infraName);
InfraNameModelImpl
public class InfraNameModelImpl implements InfraNameModel
private String infraName;
@Override
public String getInfraName()
return infraName;
@Override
public void setInfraName(String infraName)
this.infraName = infraName;
InfraNameModelList
public interface InfraNameModelList<T extends InfraNameModel>
public List<T> getInfraNameModelList();
public void setInfraNameModelList(List<T> infraNameModel);
InfraNameModelListImpl
public class InfraNameModelListImpl implements InfraNameModelList<InfraNameModel>
private List<InfraNameModel> infraNameModelList;
@Override
public List<InfraNameModel> getInfraNameModelList()
return infraNameModelList;
@Override
public void setInfraNameModelList(List<InfraNameModel> infraNameModelList)
this.infraNameModelList = infraNameModelList;
IBeanFactory
public interface IBeanFactory extends AutoBeanFactory
IBeanFactory INSTANCE = GWT.create(IBeanFactory.class);
AutoBean<InfraNameModel> infraNameModel();
AutoBean<InfraNameModelList> infraNameModelList();
...
InfraNameModelList infraNameModelList = beanFactory.deserializeFromJson(" [\"infraName\":\"TEST1\",\"infraName\":\"TEST2\"");
if (infraNameModelList == null)
logger.info("infraNameModelList=== null");
else
logger.info("infraNameModelList not null " + infraNameModelList);
List<InfraNameModelImpl> infraNameModel = infraNameModelList.getInfraNameModelList();
if (infraNameModel == null)
logger.info("infraNameModel=== null");
else
logger.info("infraNameModel=== not null " + infraNameModel);
InfraNameModelImpl infraNameModelImpl = infraNameModel.get(0);
if (infraNameModel == null)
logger.info("infraNameModelImpl=== null");
else
logger.info("infraNameModelImpl=== not null " + infraNameModelImpl);
logger.info("===" + infraNameModelImpl.getInfraName());
所以我有这样的错误 在这一行
ConsoleLogger.java:32 infraNameModel=== null
为什么 infraNameModel 为空??? =(
===SUCCESS
ConsoleLogger.java:32 ===["infraName":"TEST1","infraName":"TEST2"]
ConsoleLogger.java:32 infraNameModelList not null by.client.models.infraNameModel.InfraNameModelListAutoBean$2@36
ConsoleLogger.java:32 infraNameModel=== null
ConsoleLogger.java:32 (TypeError) : Cannot read property 'get_18_g$' of null
H3f_g$ @ ConsoleLogger.java:32
eAf_g$ @ SimpleConsoleLogHandler.java:36
szf_g$ @ Logger.java:312
rzf_g$ @ Logger.java:302
Pzf_g$ @ Logger.java:236
rad_g$ @ LogConfiguration.java:169
lab_g$ @ Impl.java:186
$9_g$ @ Impl.java:293
(anonymous) @ Impl.java:77
ConsoleLogger.java:55 Exception: com.google.gwt.core.client.javascriptException: (TypeError) : Cannot read property 'get_18_g$' of null
ConsoleLogger.java:32 TypeError: Cannot read property 'get_18_g$' of null
at uHg_g$.D$g_g$ [as onSuccess_8_g$] (Configuration.java:71)
at uHg_g$.xHg_g$ [as onSuccess_1_g$] (Configuration.java:55)
at S9f_g$.Ny_g$ [as onResponseReceived_0_g$] (AbstractRequestCallback.java:94)
at ZLc_g$.aMc_g$ [as fireOnResponseReceived_0_g$] (Request.java:250)
at hNc_g$.iNc_g$ [as onReadyStateChange_0_g$] (RequestBuilder.java:412)
at XMLHttpRequest.<anonymous> (XMLHttpRequest.java:329)
at X9_g$ (Impl.java:239)
at $9_g$ (Impl.java:291)
at XMLHttpRequest.<anonymous> (Impl.java:77)
【问题讨论】:
【参考方案1】:为什么 infraNameModel 为空??? =(
因为数组没有infraNameModelList
属性。
您必须将 JSON 数组包装到具有此类属性的对象中,以使其与您的 AutoBean 模型匹配。
【讨论】:
我刚刚读到你在 4 年前回答 groups.google.com/forum/#!topic/google-web-toolkit/8Ts07mG0Ci8。能详细描述一下吗??? [\"infraName\":\"TEST1\",\"infraName\":\"TEST2\"] ...... .. 我需要将此 JSON 包装在 "results" : [ "infraName" : "TEST1" , "infraName" : "TEST2" ] 中吗?以上是关于GWT Autobean Bean 为空的主要内容,如果未能解决你的问题,请参考以下文章