dwr 获取持久层对象报错

本文介绍了解决DWR获取Attribute列表时出现dataisnull错误的方法。通过调整Hibernate映射文件中懒加载配置或将数据库对象转换为VO对象来避免错误发生。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 dwr 获取数组列表对象,列表里的对象是数据库持久层的对象Attribute,结果在视图层,获取Attribute的值报错,在页面提示 data is null。

 根据报错信息,发现Attribute对象内的映射关系迟缓加载有问题,实例如下:

js代码:

function getAttributeSupListJ(attributePath,attributeId,newAttributeId){
    attributeDwr.getAttributeSupList(attributePath+"."+newAttId,__doCreateAttributeList);
}
function __doCreateAttributeList(data){
    if(!data) return;
    if(data.length<1) return;
    var obj=document.getElementById("att_group_1");
    var mySelect = document.createElement("select");
      mySelect.id = new_att_group_1;
      if(window.addEventListener) // Mozilla, Netscape, Firefox
    {
         mySelect.addEventListener('change', getAttributeSupListJ,false);//添加事件
    }
    else// IE
    {
         mySelect.attachEvent('onchange',getAttributeSupListJ);//添加事件
    }
    obj.appendChild(mySelect);
    if(obj){
        //DWRUtil.removeAllOptions(new_att_group_1);
        DWRUtil.addOptions(new_att_group_1,data,'catalogId','catalogName');
    }
}

DWR接口定义:

public List getAttributeSupList(String attributePath)

DWR实现类定义:

public List getAttributeSupList(String attributePath){......}

 

解决办法:

1、把Attribute.hbm.xml 的映射关系lazy="true" 改成lazy="false"

     <set name="productAttributeValues"  table="product_attribute_value" lazy="false" inverse="true" sort="unsorted">
        <key>
            <column name="attributeId"/>
        </key>
        <one-to-many class="com.dingDang.mall.common.model.catalog.ProductAttributeValue"/>
    </set>

 

2、新建一个临时存储Attribute 对象数据的 对象:

    AttributeVO {   
   
    private Integer catalogId;
    private String catalogName;
    private String path;//
    private String pathName;
    private String data;
    private String flag;
    private Object object;

   修改 DWR实现类定义:

    public List getAttributeSupList(String attributePath){
        List list = (List)attributeMenuUtil.getAttributesMap().get(attributePath);
        List results=new ArrayList();
        if(list!=null && list.size()>0){
            AttributeVo attributeVo= null;
            Attribute att = null;
            for(int i=0;i<list.size();i++){
                attributeVo= new AttributeVo ();
                att = (Attribute)list.get(i);
                attributeVo.setCatalogId(att.getAttributeId());
                attributeVo.setCatalogName(att.getAttributeName());
                attributeVo.setPath(att.getAttributePath());
                attributeVo.setData(att.getDefaultValue());
                attributeVo.setFlag(att.getInputType()+"");
                results.add(i, attributeVo);
            }
        }
        return results;
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值