src/org/tiefaces/components/websheet/utility/CommandUtility.java
@SuppressWarnings({ "rawtypes" })
	public static int deleteRow(final ConfigBuildRef configBuildRef,
			final int rowIndex, final Map<String, Object> dataContext,
			final SheetConfiguration sheetConfig,
			final List<FacesRow> bodyRows) {

		String fullName = ConfigurationUtility.getFullNameFromRow(
				configBuildRef.getSheet().getRow(rowIndex));

		configBuildRef.getCellHelper().restoreDataContext(fullName);
		CollectionObject collect = configBuildRef.getCellHelper()
				.getLastCollect(fullName);

		Collection lastCollection = collect.getLastCollection();
		int lastCollectionIndex = collect.getLastCollectionIndex();
		EachCommand eachCommand = collect.getEachCommand();
		if (lastCollectionIndex < 0) {
			// no each command in the loop.
			throw new DeleteRowException("No each command found.");
		}
		if (lastCollection.size() <= 1) {
			// this is the last record and no parent left.
			throw new DeleteRowException(
					"Cannot delete the last record in the group.");
		}

		CommandUtility.deleteObjectInContext(lastCollection, eachCommand,
				lastCollectionIndex, dataContext);

		// find range from shiftmap.
		ConfigRangeAttrs currentRangeAttrs = configBuildRef.getShiftMap()
				.get(fullName);
		if (currentRangeAttrs == null) {
			throw new DeleteRowException("Cannot find delete range.");

		}

		// The lastRowRef is wrong in rangeAttrs. So use length to recalc it.
		int startRow = currentRangeAttrs.getFirstRowIndex();
		int length = currentRangeAttrs.getFinalLength();
		int endRow = startRow + length - 1;

		List<String> removeFullNameList = findRemoveFullNameList(
				configBuildRef.getSheet(), startRow, endRow);
		// remove range from shiftmap.
		removeRangesFromShiftMap(configBuildRef.getShiftMap(),
				removeFullNameList);
		// 1. remove ranged rows from sheet
		String var = eachCommand.getVar();
		CommandUtility.removeRowsInSheet(configBuildRef.getSheet(),
				startRow, endRow, configBuildRef.getCachedCells());
		// 2. reset FacesRow row index.
		CommandUtility.removeRowsInBody(sheetConfig, bodyRows, startRow,
				endRow);
		// 3. decrease index number in hidden column
		Map<String, String> changeMap = new TreeMap<>();
		ConfigurationUtility.changeIndexNumberInHiddenColumn(configBuildRef,
				startRow, fullName, changeMap, -1);
		// 4. decrease index number in shift map
		ConfigurationUtility.changeIndexNumberInShiftMap(
				configBuildRef.getShiftMap(), changeMap);
		// 5. rebuild upper level formula
		ConfigurationUtility.reBuildUpperLevelFormula(configBuildRef,
				fullName);
		// 6. decrease upper level final length
		ConfigurationUtility.changeUpperLevelFinalLength(
				configBuildRef.getShiftMap(), fullName, -length);

		dataContext.remove(var);

		return length;

	}
@SuppressWarnings({ "rawtypes" })
	public static int deleteRow(final ConfigBuildRef configBuildRef,
			final int rowIndex, final Map<String, Object> dataContext,
			final SheetConfiguration sheetConfig,
			final List<FacesRow> bodyRows) {

		String fullName = ConfigurationUtility.getFullNameFromRow(
				configBuildRef.getSheet().getRow(rowIndex));

		configBuildRef.getCellHelper().restoreDataContext(fullName);
		CollectionObject collect = configBuildRef.getCellHelper()
				.getLastCollect(fullName);

		Collection lastCollection = collect.getLastCollection();
		int lastCollectionIndex = collect.getLastCollectionIndex();
		EachCommand eachCommand = collect.getEachCommand();
		if (lastCollectionIndex < 0) {
			// no each command in the loop.
			throw new DeleteRowException("No each command found.");
		}
		if (lastCollection.size() <= 1) {
			// this is the last record and no parent left.
			throw new DeleteRowException(
					"Cannot delete the last record in the group.");
		}

		CommandUtility.deleteObjectInContext(lastCollection, eachCommand,
				lastCollectionIndex, dataContext);

		// find range from shiftmap.
		ConfigRangeAttrs currentRangeAttrs = configBuildRef.getShiftMap()
				.get(fullName);
		if (currentRangeAttrs == null) {
			throw new DeleteRowException("Cannot find delete range.");

		}

		// The lastRowRef is wrong in rangeAttrs. So use length to recalc it.
		int startRow = currentRangeAttrs.getFirstRowIndex();
		int length = currentRangeAttrs.getFinalLength();
		int endRow = startRow + length - 1;

		List<String> removeFullNameList = findRemoveFullNameList(
				configBuildRef.getSheet(), startRow, endRow);
		// remove range from shiftmap.
		removeRangesFromShiftMap(configBuildRef.getShiftMap(),
				removeFullNameList);
		// 1. remove ranged rows from sheet
		String var = eachCommand.getVar();
		CommandUtility.removeRowsInSheet(configBuildRef.getSheet(),
				startRow, endRow, configBuildRef.getCachedCells());
		// 2. reset FacesRow row index.
		CommandUtility.removeRowsInBody(sheetConfig, bodyRows, startRow,
				endRow);
		// 3. decrease index number in hidden column
		Map<String, String> changeMap = new TreeMap<>();
		ConfigurationUtility.changeIndexNumberInHiddenColumn(configBuildRef,
				startRow, fullName, changeMap, -1);
		// 4. decrease index number in shift map
		ConfigurationUtility.changeIndexNumberInShiftMap(
				configBuildRef.getShiftMap(), changeMap);
		// 5. rebuild upper level formula
		ConfigurationUtility.reBuildUpperLevelFormula(configBuildRef,
				fullName);
		// 6. decrease upper level final length
		ConfigurationUtility.changeUpperLevelFinalLength(
				configBuildRef.getShiftMap(), fullName, -length);

		dataContext.remove(var);

		return length;

	}
Delete row.

@param configBuildRef
the config build ref
@param rowIndex
the row index
@param dataContext
the data context
@param sheetConfig
the sheet config
@param bodyRows
the body rows
@return the int
@throws DeleteRowException
the delete row exception