開源俱樂部

          開源框架
            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);
          主站蜘蛛池模板: 依兰县| 竹北市| 兴文县| 溧阳市| 玉林市| 包头市| 西林县| 定襄县| 三亚市| 喀喇| 鸡东县| 肥西县| 平昌县| 行唐县| 井冈山市| 新巴尔虎右旗| 山阳县| 彭水| 淮安市| 灵璧县| 鄂伦春自治旗| 潍坊市| 旅游| 澄城县| 潼南县| 来安县| 盘山县| 淳化县| 青岛市| 清苑县| 安龙县| 新沂市| 银川市| 博白县| 维西| 金湖县| 赤壁市| 横山县| 临潭县| 绍兴市| 永修县|