Jakarta ee 从JavaScript检索struts2中的Action类的值

Jakarta ee 从JavaScript检索struts2中的Action类的值,jakarta-ee,jqgrid,struts2,struts2-jquery,Jakarta Ee,Jqgrid,Struts2,Struts2 Jquery,我正在使用jQueryStruts2网格插件。我正在使用自己的表单更新、删除和插入对象。我已经创建了一个隐藏字段来从javascript检索值,但它不起作用。。。有什么问题吗 当我单击时,下面的网格代码被激活 var product_id = grid.jqGrid('getCell', sel_id, 'product_Id'); 我想通过以下方式将product_id的值传递给struts2中的隐藏标记 document.getElementById('product_Id').valu

我正在使用jQueryStruts2网格插件。我正在使用自己的表单更新、删除和插入对象。我已经创建了一个隐藏字段来从javascript检索值,但它不起作用。。。有什么问题吗

当我单击时,下面的网格代码被激活

var product_id = grid.jqGrid('getCell', sel_id, 'product_Id'); 
我想通过以下方式将product_id的值传递给struts2中的隐藏标记

document.getElementById('product_Id').value = product_id;
因此,它应该通过这个标记将product_id值传递给product_Key字段

<s:hidden value="" name="product_Key" id="product_Id"/>
整个代码都受影响

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>
<!DOCTYPE html>
<html>
    <head>
        <sj:head jqueryui="true" jquerytheme="redmond" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>

        <s:url id="remoteurl" action="ProductMain"/>
        <s:url id="editurl" action="ProductUpdate">
            <s:param name="product_Key"><s:property value="product_Key"/></s:param>
        </s:url>



        <s:url id="myUrl" action="ProductInitialise" />
        <s:hidden value="" name="product_Key" id="product_Id"/>   -----> use to retrieve value of product id

        <script type="text/javascript">
            // this will retrieve the record in the row.. retrieve this for delete and edit.
            $.subscribe('rowselect', function(event, data) {
                var grid = event.originalEvent.grid; 
                var sel_id = grid.jqGrid('getGridParam', 'selrow'); 
                var product_id = grid.jqGrid('getCell', sel_id, 'product_Id'); 
                var last_date =  grid.jqGrid('getCell', sel_id, 'last_Date'); 
                alert(product_id + 'date' + last_date);
                document.getElementById('product_Id').value = product_id; ---> paste the value of the product_id.
                //  alert('Selected Row : ' + event.originalEvent.id );
            });





        </script>




        <sjg:grid
            id="gridtable"
            caption="Customer Examples"
            dataType="json"
            href="%{remoteurl}"
            pager="true"
            gridModel="gridModel"
            rowList="10,15,20"
            rowNum="10"
            rownumbers="true"

            navigatorExtraButtons="{
            seperator: { 
            title : 'seperator'  
            }, 
            Insert : { 
            title : 'Insert Record', 
            caption : 'Insert', 
            icon: 'ui-icon-plusthick', 
            onclick: function(){  alert('Grid Button clicked!') ,window.location = '%{myUrl}'} 
            },
            Edit : { 
            title :'Edit record on the selected record on the row',
            caption :'Edit Record', 
            icon:'ui-icon-pencil',
            onclick: function(){ alert('Edit is clicked'),window.location = '%{editurl}' }
            }
            }"
            navigatorAdd="false"
            navigatorEdit="false"
            navigator="true"
            resizable="true"
            onSelectRowTopics="rowselect"
            >


            <sjg:gridColumn name="product_Id" 
                            index="product_Id" 
                            title="Product_Id"  
                            sortable="false"
                            />


            <sjg:gridColumn name="serial_Number" 
                            index="serial_Number" 
                            title="Serial_Number" 
                            editable="true"
                            sortable="true"/>
            <sjg:gridColumn name="date_Assembled" 
                            index="date_Assembled" 
                            title="Date_Assembled"  
                            editable="true"
                            sortable="true"/>
            <sjg:gridColumn name="time_Assembled" 
                            index="time_Assembled" 
                            title="Time_Assembled" 
                            editable="true"
                            sortable="true"/>
            <sjg:gridColumn name="model" 
                            index="model" 
                            title="Model"  
                            editable="true"
                            sortable="true"/>
            <sjg:gridColumn name="batch_Id" 
                            index="batch_Id" 
                            title="Batch_Id" 
                            sortable="true"/>
            <sjg:gridColumn name="process_Code" 
                            index="process_Code" 
                            title="Process_Code"  
                            editable="true"
                            sortable="false"/>
            <sjg:gridColumn name="dc_Power_PCB_Serial" 
                            index="dc_Power_PCB_Serial" 
                            title="Dc_Power_PCB_Serial" 

                            editable="true"
                            sortable="dc_Power_PCB_Serial"/>
            <sjg:gridColumn name="control_Power_PCB_Serial" 
                            index="control_Power_PCB_Serial" 
                            title="Control_Power_PCB_Serial" 
                            editable="true"
                            sortable="control_Power_PCB_Serial"/>
            <sjg:gridColumn name="mains_Power_PCB_Serial" 
                            index="mains_Power_PCB_Serial" 
                            title="Mains_Power_PCB_Serial" 
                            editable="true"
                            sortable="mains_Power_PCB_Serial"/>
            <sjg:gridColumn name="blower_Serial" 
                            index="blower_Serial" 
                            title="Blower_Serial" 
                            editable="true"
                            sortable="blower_Serial"/>
            <sjg:gridColumn name="heaterPlate_Serial" 
                            index="heaterPlate_Serial" 
                            title="HeaterPlate_Serial" 
                            editable="true"
                            sortable="heaterPlate_Serial"/>
            <sjg:gridColumn name="last_Process" 
                            index="last_Process" 
                            title="Last_Process" 
                            editable="true"
                            sortable="last_Process"/>
            <sjg:gridColumn name="last_Date" 
                            index="last_Date"  
                            formatter="date" 
                            formatoptions="{newformat : 'd.m.Y H:i', srcformat : 'Y-m-d H:i:s'}"
                            editable="true"
                            title="Last_Date" sortable="last_Date"/>
            <sjg:gridColumn name="updatedTime" 
                            index="updatedTime" 
                            title="UpdatedTime" 
                            sortable="updatedTime"/>




        </sjg:grid>
    </body>
</html>

尝试在



我认为您的想法是正确的,但产品密钥仍然没有价值。。。我认为这些代码不起作用?document.getElementById('product_Id')。value=product_Id;product_id来自var product_id=grid.jqGrid('getCell',sel_id',product_id');它应该传递值…我更新了我的问题,并将您的答案作为解决方案的一部分
 Edit : { 
            title :'Edit record on the selected record on the row',
            caption :'Edit Record', 
            icon:'ui-icon-pencil',
            onclick: function(){ alert('Edit is clicked'),document.getElementById('product_Id').value = product_id,window.location = '%{editurl}' }
            }
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>
<!DOCTYPE html>
<html>
    <head>
        <sj:head jqueryui="true" jquerytheme="redmond" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>

        <s:url id="remoteurl" action="ProductMain"/>
        <s:url id="editurl" action="ProductUpdate">
            <s:param name="product_Key"><s:property value="product_Key"/></s:param>
        </s:url>



        <s:url id="myUrl" action="ProductInitialise" />
        <s:hidden value="" name="product_Key" id="product_Id"/>   -----> use to retrieve value of product id

        <script type="text/javascript">
            // this will retrieve the record in the row.. retrieve this for delete and edit.
            $.subscribe('rowselect', function(event, data) {
                var grid = event.originalEvent.grid; 
                var sel_id = grid.jqGrid('getGridParam', 'selrow'); 
                var product_id = grid.jqGrid('getCell', sel_id, 'product_Id'); 
                var last_date =  grid.jqGrid('getCell', sel_id, 'last_Date'); 
                alert(product_id + 'date' + last_date);
                document.getElementById('product_Id').value = product_id; ---> paste the value of the product_id.
                //  alert('Selected Row : ' + event.originalEvent.id );
            });





        </script>




        <sjg:grid
            id="gridtable"
            caption="Customer Examples"
            dataType="json"
            href="%{remoteurl}"
            pager="true"
            gridModel="gridModel"
            rowList="10,15,20"
            rowNum="10"
            rownumbers="true"

            navigatorExtraButtons="{
            seperator: { 
            title : 'seperator'  
            }, 
            Insert : { 
            title : 'Insert Record', 
            caption : 'Insert', 
            icon: 'ui-icon-plusthick', 
            onclick: function(){  alert('Grid Button clicked!') ,window.location = '%{myUrl}'} 
            },
            Edit : { 
            title :'Edit record on the selected record on the row',
            caption :'Edit Record', 
            icon:'ui-icon-pencil',
            onclick: function(){ alert('Edit is clicked'),window.location = '%{editurl}' }
            }
            }"
            navigatorAdd="false"
            navigatorEdit="false"
            navigator="true"
            resizable="true"
            onSelectRowTopics="rowselect"
            >


            <sjg:gridColumn name="product_Id" 
                            index="product_Id" 
                            title="Product_Id"  
                            sortable="false"
                            />


            <sjg:gridColumn name="serial_Number" 
                            index="serial_Number" 
                            title="Serial_Number" 
                            editable="true"
                            sortable="true"/>
            <sjg:gridColumn name="date_Assembled" 
                            index="date_Assembled" 
                            title="Date_Assembled"  
                            editable="true"
                            sortable="true"/>
            <sjg:gridColumn name="time_Assembled" 
                            index="time_Assembled" 
                            title="Time_Assembled" 
                            editable="true"
                            sortable="true"/>
            <sjg:gridColumn name="model" 
                            index="model" 
                            title="Model"  
                            editable="true"
                            sortable="true"/>
            <sjg:gridColumn name="batch_Id" 
                            index="batch_Id" 
                            title="Batch_Id" 
                            sortable="true"/>
            <sjg:gridColumn name="process_Code" 
                            index="process_Code" 
                            title="Process_Code"  
                            editable="true"
                            sortable="false"/>
            <sjg:gridColumn name="dc_Power_PCB_Serial" 
                            index="dc_Power_PCB_Serial" 
                            title="Dc_Power_PCB_Serial" 

                            editable="true"
                            sortable="dc_Power_PCB_Serial"/>
            <sjg:gridColumn name="control_Power_PCB_Serial" 
                            index="control_Power_PCB_Serial" 
                            title="Control_Power_PCB_Serial" 
                            editable="true"
                            sortable="control_Power_PCB_Serial"/>
            <sjg:gridColumn name="mains_Power_PCB_Serial" 
                            index="mains_Power_PCB_Serial" 
                            title="Mains_Power_PCB_Serial" 
                            editable="true"
                            sortable="mains_Power_PCB_Serial"/>
            <sjg:gridColumn name="blower_Serial" 
                            index="blower_Serial" 
                            title="Blower_Serial" 
                            editable="true"
                            sortable="blower_Serial"/>
            <sjg:gridColumn name="heaterPlate_Serial" 
                            index="heaterPlate_Serial" 
                            title="HeaterPlate_Serial" 
                            editable="true"
                            sortable="heaterPlate_Serial"/>
            <sjg:gridColumn name="last_Process" 
                            index="last_Process" 
                            title="Last_Process" 
                            editable="true"
                            sortable="last_Process"/>
            <sjg:gridColumn name="last_Date" 
                            index="last_Date"  
                            formatter="date" 
                            formatoptions="{newformat : 'd.m.Y H:i', srcformat : 'Y-m-d H:i:s'}"
                            editable="true"
                            title="Last_Date" sortable="last_Date"/>
            <sjg:gridColumn name="updatedTime" 
                            index="updatedTime" 
                            title="UpdatedTime" 
                            sortable="updatedTime"/>




        </sjg:grid>
    </body>
</html>
    package lotmovement.action;

    import com.opensymphony.xwork2.*;
    import java.util.Date;
    import lotmovement.business.crud.ProductCrud;
    import lotmovement.business.crud.RecordExistProduct;
    import lotmovement.business.crud.crudinterface.CrudInterface;
    import lotmovement.business.entity.Product;
    import org.apache.struts2.interceptor.validation.SkipValidation;


    public class ProductAction extends ActionSupport implements CrudInterface {

        private Long product_Id;
        private String serial_Number;
        private String date_Assembled;
        private String time_Assembled;
        private String model;
        private int batch_Id;
        private int process_Code;
        private String dc_Power_PCB_Serial;
        private String control_Power_PCB_Serial;
        private String mains_Power_PCB_Serial;
        private String blower_Serial;
        private String heaterPlate_Serial;
        private String last_Process;
        private String last_Date;

        private Date today;
        private Long product_Key; --> this is the hidden field


        ProductCrud productCrud;

        RecordExistProduct recordExistProduct;

        Product product;

        public Product getProduct() {
            return product;
        }

        public void setProduct(Product product) {
            this.product = product;
        }



        public ProductCrud getProductCrud() {
            return productCrud;
        }

        public void setProductCrud(ProductCrud productCrud) {
            this.productCrud = productCrud;
        }

        public RecordExistProduct getRecordExistProduct() {
            return recordExistProduct;
        }

        public void setRecordExistProduct(RecordExistProduct recordExistProduct) {
            this.recordExistProduct = recordExistProduct;
        }



        @Override
        public void validate() {
          setToday(new Date());

          if(recordExistProduct.ProductExist(getSerial_Number())==true){
                addActionError("Record already exist. Please use another Serial Number");
          }

        }

        @Override

        public String execute() {
          setToday(new Date());

            return SUCCESS;
        }

        @SkipValidation
        public String Initialise_Product(){

              setToday(new Date());
              return SUCCESS;
        }

        @Override
        @SkipValidation
        public void Update() {

        PopulateProduct();     
        }

        @Override
        @SkipValidation
        public void Insert() {

            PopulateProduct();
            productCrud.Insert(product);



        }

        @Override
        @SkipValidation
        public void Delete() {
            throw new UnsupportedOperationException("Not supported yet.");
        }


        public void PopulateProduct()
        {
            product.setProduct_Id(getProduct_Id());
            product.setSerial_Number(getSerial_Number());
            product.setDate_Assembled(getDate_Assembled());
            product.setTime_Assembled(getTime_Assembled());
            product.setModel(getModel());
            product.setBatch_Id(getBatch_Id());
            product.setProcess_Code(getProcess_Code());
            product.setDc_Power_PCB_Serial(getDc_Power_PCB_Serial());
            product.setControl_Power_PCB_Serial(getControl_Power_PCB_Serial());
            product.setMains_Power_PCB_Serial(getMains_Power_PCB_Serial());
            product.setBlower_Serial(getBlower_Serial());
            product.setHeaterPlate_Serial(getHeaterPlate_Serial());
            product.setLast_Process(getLast_Process());
            product.setLast_Date(getLast_Date());
        }











        public Long getProduct_Id() {
            return product_Id;
        }

        public void setProduct_Id(Long product_Id) {
            this.product_Id = product_Id;
        }

        public String getSerial_Number() {
            return serial_Number;
        }

        public void setSerial_Number(String serial_Number) {
            this.serial_Number = serial_Number;
        }

        public String getDate_Assembled() {
            return date_Assembled;
        }

        public void setDate_Assembled(String date_Assembled) {
            this.date_Assembled = date_Assembled;
        }

        public String getTime_Assembled() {
            return time_Assembled;
        }

        public void setTime_Assembled(String time_Assembled) {
            this.time_Assembled = time_Assembled;
        }

        public String getModel() {
            return model;
        }

        public void setModel(String model) {
            this.model = model;
        }

        public int getBatch_Id() {
            return batch_Id;
        }

        public void setBatch_Id(int batch_Id) {
            this.batch_Id = batch_Id;
        }

        public int getProcess_Code() {
            return process_Code;
        }

        public void setProcess_Code(int process_Code) {
            this.process_Code = process_Code;
        }

        public String getDc_Power_PCB_Serial() {
            return dc_Power_PCB_Serial;
        }

        public void setDc_Power_PCB_Serial(String dc_Power_PCB_Serial) {
            this.dc_Power_PCB_Serial = dc_Power_PCB_Serial;
        }

        public String getControl_Power_PCB_Serial() {
            return control_Power_PCB_Serial;
        }

        public void setControl_Power_PCB_Serial(String control_Power_PCB_Serial) {
            this.control_Power_PCB_Serial = control_Power_PCB_Serial;
        }

        public String getMains_Power_PCB_Serial() {
            return mains_Power_PCB_Serial;
        }

        public void setMains_Power_PCB_Serial(String mains_Power_PCB_Serial) {
            this.mains_Power_PCB_Serial = mains_Power_PCB_Serial;
        }

        public String getBlower_Serial() {
            return blower_Serial;
        }

        public void setBlower_Serial(String blower_Serial) {
            this.blower_Serial = blower_Serial;
        }

        public String getHeaterPlate_Serial() {
            return heaterPlate_Serial;
        }

        public void setHeaterPlate_Serial(String heaterPlate_Serial) {
            this.heaterPlate_Serial = heaterPlate_Serial;
        }

        public String getLast_Process() {
            return last_Process;
        }

        public void setLast_Process(String last_Process) {
            this.last_Process = last_Process;
        }

        public String getLast_Date() {
            return last_Date;
        }

        public void setLast_Date(String last_Date) {
            this.last_Date = last_Date;
        }

          public Date getToday() {
            return today;
        }

        public void setToday(Date Today) {
            this.today = Today;
        }

        public Long getProduct_Key() {
            return product_Key;
        }

        public void setProduct_Key(Long product_Key) {
            this.product_Key = product_Key;
        }



    }
<s:url id="remoteurl" action="ProductMain" namespace="/">
   <s:param name="product_Key"><s:property value="product_Key"/></s:param>
</s:url>