開源俱樂部

          開源框架

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

          以下是比較好的解決方案:
          利用apache的common類中的BeanUtils來實現(xiàn)對象屬性的復(fù)制
          if (j == rowId && !line[j].getNewRecord()) {
               
                 
                 CreateDeliveryLineRow row = new CreateDeliveryLineRow();
                 BeanUtils.copyProperties(row,line[j]);   //復(fù)制出對象line[j],將其屬性賦予row
                 row.setQuantity(null);                                     //在row中輕松的實現(xiàn)對某幾個屬性的控制
                 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);
          主站蜘蛛池模板: 荥阳市| 钦州市| 云霄县| 武强县| 华亭县| 海城市| 抚松县| 建湖县| 永康市| 涞水县| 广平县| 宣武区| 靖边县| 博乐市| 靖远县| 林周县| 大埔县| 定州市| 黄梅县| 松江区| 岚皋县| 新民市| 自治县| 岢岚县| 德阳市| 河西区| 鹤峰县| 兰坪| 辽宁省| 德惠市| 夏津县| 台山市| 华宁县| 同心县| 甘泉县| 桑日县| 河北区| 阿勒泰市| 久治县| 九龙坡区| 资溪县|