Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Struts2 表格数据结构_Struts2_Tabular_Actioncontext - Fatal编程技术网

Struts2 表格数据结构

Struts2 表格数据结构,struts2,tabular,actioncontext,Struts2,Tabular,Actioncontext,我尝试从主详细信息表单捕获数据,返回JSON对象,如下所示我的表单与此相似我遵循此指南我可以捕获主数据,但如何访问详细信息?我现在得到的结果是 {"codigo":"RQ-201000-1210-00001","fecha":"Oct 25, 2012 12:00:00 AM","dreqproductos":[]} 我的表格是: 如何获得dreqproductos <input name="reqproducto.codigo" /> <input name="reqp

我尝试从主详细信息表单捕获数据,返回JSON对象,如下所示我的表单与此相似我遵循此指南我可以捕获主数据,但如何访问详细信息?我现在得到的结果是

{"codigo":"RQ-201000-1210-00001","fecha":"Oct 25, 2012 12:00:00 AM","dreqproductos":[]}
我的表格是:

如何获得dreqproductos

<input name="reqproducto.codigo"   />
<input name="reqproducto.fecha"   />

<input name="reqproducto.dreqproductos[1].masterproducto"   />
<input name="reqproducto.dreqproductos[1].cantidad"         />

<input name="reqproducto.dreqproductos[2].masterproducto"   />
<input name="reqproducto.dreqproductos[2].cantidad"         />

我的行动是

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package actions;

import com.google.gson.Gson;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import hibernate.domain.Centrocosto;
import hibernate.domain.Dreqproducto;
import hibernate.domain.Reqproducto;
import hibernate.util.hibernateUtil;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.*;
import model.dao.impl.DaoReqproductoImpl;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
/**
 *
 * @author DEV11
 */
public class ActionReqProducto extends ActionSupport{

    private InputStream inputStream;
    public InputStream getInputStream() {
        return inputStream;
    }

    public Reqproducto reqproducto;
    public void setReqproducto(Reqproducto reqproducto) {
        this.reqproducto = reqproducto;
    }

    public String ReqproductoIns() throws UnsupportedEncodingException {
        //CAPTURA
        String msg = "VOID";
        Session session = hibernateUtil.getSessionFactory().getCurrentSession();
        //Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction transaction = null;

        try {
            transaction = session.beginTransaction();

            //////////////////////////////////////////////////////////////
            if (reqproducto.getId() == null) {//INSERTAR
                //CABECERA INSERTAR GERISTRO
                session.save(reqproducto);

                msg = "INSERT ";
            } else {//ACTUALIZAR
                //CABECERA ACTUALIZAR REGISTRO
                String queryString = "from Reqproducto where id = :id";
                Query query = session.createQuery(queryString);
                query.setInteger("id", reqproducto.getId());
                session.update(reqproducto);

                msg = "UPDATE ";
            }
            //////////////////////////////////////////////////////////////

            //session.getTransaction().commit();
            transaction.commit();

            msg += "OK" + reqproducto.getId();//+session.getIdentifier(reqproducto);;
        } catch (HibernateException e) {
            transaction.rollback();
            //e.printStackTrace();
            msg = "ERROR: " + e.getMessage();
        } finally {
            //session.close();
        }

        //RESPUESTA
        Gson gson = new Gson();
        //String json  = "{cabecera:{'id':'"+id+"','codigo':'"+codigo+"','descripcion':'"+descripcion+"','abreviatura':'"+abreviatura+"','visible':'"+visible+"'}, msg:'Devolviendo Resultado via Ajax en \"Español\"'}";
        String json = gson.toJson(this.reqproducto);
        inputStream = new ByteArrayInputStream(json.getBytes("UTF-8"));
        return SUCCESS;
    }
}

集合在json序列化之前存在吗?您使用什么进行序列化?是struts2 json插件吗?我正在使用gson,我可以发送mi项目吗?我正在使用netbeans
public class Dreqproducto  implements java.io.Serializable {
     private Integer id;
     private Masterproducto masterproducto;
     private Reqproducto reqproducto;
     private BigDecimal cantidad;
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package actions;

import com.google.gson.Gson;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import hibernate.domain.Centrocosto;
import hibernate.domain.Dreqproducto;
import hibernate.domain.Reqproducto;
import hibernate.util.hibernateUtil;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.*;
import model.dao.impl.DaoReqproductoImpl;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
/**
 *
 * @author DEV11
 */
public class ActionReqProducto extends ActionSupport{

    private InputStream inputStream;
    public InputStream getInputStream() {
        return inputStream;
    }

    public Reqproducto reqproducto;
    public void setReqproducto(Reqproducto reqproducto) {
        this.reqproducto = reqproducto;
    }

    public String ReqproductoIns() throws UnsupportedEncodingException {
        //CAPTURA
        String msg = "VOID";
        Session session = hibernateUtil.getSessionFactory().getCurrentSession();
        //Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction transaction = null;

        try {
            transaction = session.beginTransaction();

            //////////////////////////////////////////////////////////////
            if (reqproducto.getId() == null) {//INSERTAR
                //CABECERA INSERTAR GERISTRO
                session.save(reqproducto);

                msg = "INSERT ";
            } else {//ACTUALIZAR
                //CABECERA ACTUALIZAR REGISTRO
                String queryString = "from Reqproducto where id = :id";
                Query query = session.createQuery(queryString);
                query.setInteger("id", reqproducto.getId());
                session.update(reqproducto);

                msg = "UPDATE ";
            }
            //////////////////////////////////////////////////////////////

            //session.getTransaction().commit();
            transaction.commit();

            msg += "OK" + reqproducto.getId();//+session.getIdentifier(reqproducto);;
        } catch (HibernateException e) {
            transaction.rollback();
            //e.printStackTrace();
            msg = "ERROR: " + e.getMessage();
        } finally {
            //session.close();
        }

        //RESPUESTA
        Gson gson = new Gson();
        //String json  = "{cabecera:{'id':'"+id+"','codigo':'"+codigo+"','descripcion':'"+descripcion+"','abreviatura':'"+abreviatura+"','visible':'"+visible+"'}, msg:'Devolviendo Resultado via Ajax en \"Español\"'}";
        String json = gson.toJson(this.reqproducto);
        inputStream = new ByteArrayInputStream(json.getBytes("UTF-8"));
        return SUCCESS;
    }
}