0

jquery struts2 グリッド プラグインを使用しています。オブジェクトを更新、削除、挿入するために独自のフォームを使用しています。javascript から値を取得するための非表示フィールドを作成しましたが、機能しませんでした... 何が問題なのですか?

クリックすると、下のグリッド コードがアクティブになります。

var product_id = grid.jqGrid('getCell', sel_id, 'product_Id'); 

これでstruts2のhiddenタグにproduct_idの値を渡したい。

document.getElementById('product_Id').value = product_id;

したがって、このタグを介して product_id 値を product_Key フィールドに渡す必要があります。

<s:hidden value="" name="product_Key" id="product_Id"/>

次に、グリッドの編集ボタンをクリックすると、この行を介してパラメータとして渡されます。

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

これが編集クリックボタンです。

 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;
        }



    }
4

1 に答える 1

0

内部にパラメータを渡してみてください<s:url>

<s:url id="remoteurl" action="ProductMain" namespace="/">
   <s:param name="product_Key"><s:property value="product_Key"/></s:param>
</s:url>
于 2013-02-25T07:20:02.433 に答える