開源俱樂部

          開源框架
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          在Strut中,實現table中復制一行的功能
          line[j]是要復制的一行,Action中可以獲取到要復制的行的ID.
          因為line[j]中有很多屬性,要是一個一個的屬性去get,然后set的話,代碼量會
          很大,而且會出現很多冗余代碼。
          這是我要復制出來的一行
          if (j == rowId && !line[j].getNewRecord()) {
               rowList.add(line[j]);
               //將這一行全部復制
              }
          現在要使得其中的某幾個屬性復制出來為空
          則需要一個一個的set,get.
          if (j == rowId && !line[j].getNewRecord()) {
              CreateDeliveryLineRow  cdlr = new CreateDeliveryLineRow  ();
              if(line[j].getMfgLot() != null){
                   cdlr.setMfgLot = null;
             }
          。。。。。。
               rowList.add(cdlr);
               //將這一行全部復制
              }

          以下是比較好的解決方案:
          利用apache的common類中的BeanUtils來實現對象屬性的復制
          if (j == rowId && !line[j].getNewRecord()) {
               
                 
                 CreateDeliveryLineRow row = new CreateDeliveryLineRow();
                 BeanUtils.copyProperties(row,line[j]);   //復制出對象line[j],將其屬性賦予row
                 row.setQuantity(null);                                     //在row中輕松的實現對某幾個屬性的控制
                 row.setMfgLot(null);
                 row.setMiniQuantity(null);
                 row.setBoxQuantity(null);
                rowList.add(row);
                //rowList.add(cdr);
              }
          ===================================================
          CreateDeliveryForm getForm = (CreateDeliveryForm) form;
          。。。。。。
          CreateDeliveryLineRow[] line = getForm.getLine();
          if (line != null && line instanceof CreateDeliveryLineRow[]) {
             int size = line.length;

             for (int j = 0; j < size; j++) {
              if (!line[j].getNewRecord() && !line[j+1].getNewRecord()) {
               if (line[j].getBoxQuantity() == 0L) {
                line[j].setBoxQuantity(null);
               }
               if (line[j].getMiniQuantity() == 0L) {
                line[j].setMiniQuantity(null);
               }
               if (line[j].getQuantity() == 0D) {
                line[j].setQuantity(null);
               }
               rowList.add(line[j]);
              }
              if (j == rowId && !line[j].getNewRecord()) {
               
                 
                 CreateDeliveryLineRow row = new CreateDeliveryLineRow();
                 BeanUtils.copyProperties(row,line[j]);
                 row.setQuantity(null);
                 row.setMfgLot(null);
                 row.setMiniQuantity(null);
                 row.setBoxQuantity(null);
                 rowList.add(row);
                //rowList.add(cdr);
              }

             }
            }

          。。。。。。
          request.setAttribute("results", rowList);
          主站蜘蛛池模板: 汉阴县| 满洲里市| 正镶白旗| 克东县| 扬州市| 富源县| 莲花县| 敦煌市| 永顺县| 石渠县| 伊宁县| 红桥区| 兴城市| 乌苏市| 靖远县| 镇安县| 清新县| 神农架林区| 陵水| 弥渡县| 鹤峰县| 高平市| 科技| 什邡市| 濮阳县| 区。| 宜良县| 阿荣旗| 资溪县| 古交市| 广元市| 安西县| 白山市| 巨野县| 西峡县| 雷州市| 义马市| 花垣县| 博爱县| 鹤岗市| 土默特右旗|