private void setRowIndexRowStatePreserved(int rowIndex) {
        if (rowIndex < -1) {
            throw new IllegalArgumentException("rowIndex is less than -1");
        }

        if (getRowIndex() == rowIndex) {
            return;
        }

        FacesContext facesContext = getFacesContext();

        if (_initialDescendantFullComponentState != null) {
            //Just save the row
            Map<String, Object> sm = saveFullDescendantComponentStates(facesContext, null, getChildren().iterator(), false);
            if (sm != null && !sm.isEmpty()) {
                _rowDeltaStates.put(getContainerClientId(facesContext), sm);
            }

            if (getRowIndex() != -1) {
                _rowTransientStates.put(getContainerClientId(facesContext),
                               saveTransientDescendantComponentStates(facesContext, null, getChildren().iterator(), false));
            }
        }

        // Update to the new row index
        //this.rowIndex = rowIndex;
        getStateHelper().put(PropertyKeys.rowIndex, rowIndex);
        DataModel localModel = getDataModel();
        localModel.setRowIndex(rowIndex);

        // if rowIndex is -1, clear the cache
        if (rowIndex == -1) {
            setDataModel(null);
        }

        // Clear or expose the current row data as a request scope attribute
        String var = getVar();
        if (var != null) {
            Map<String, Object> requestMap
                    = getFacesContext().getExternalContext().getRequestMap();
            if (rowIndex == -1) {
                oldVar = requestMap.remove(var);
            }
            else if (isRowAvailable()) {
                requestMap.put(var, getRowData());
            }
            else {
                requestMap.remove(var);
                if (null != oldVar) {
                    requestMap.put(var, oldVar);
                    oldVar = null;
                }
            }
        }

        if (_initialDescendantFullComponentState != null) {
            Object rowState = _rowDeltaStates.get(getContainerClientId(facesContext));
            if (rowState == null) {
                //Restore as original
                restoreFullDescendantComponentStates(facesContext, getChildren().iterator(), _initialDescendantFullComponentState, false);
            }
            else {
                //Restore first original and then delta
                restoreFullDescendantComponentDeltaStates(facesContext, getChildren().iterator(), rowState, _initialDescendantFullComponentState, false);
            }
            if (getRowIndex() == -1) {
                restoreTransientDescendantComponentStates(facesContext, getChildren().iterator(), null, false);
            }
            else {
                rowState = _rowTransientStates.get(getContainerClientId(facesContext));
                if (rowState == null) {
                    restoreTransientDescendantComponentStates(facesContext, getChildren().iterator(), null, false);
                }
                else {
                    restoreTransientDescendantComponentStates(facesContext, getChildren().iterator(), (Map<String, Object>) rowState, false);
                }
            }
        }
    }
private void setRowIndexRowStatePreserved ( int rowIndex ) { if ( rowIndex < - 1 ) { throw new IllegalArgumentException ( "rowIndex is less than -1" ) ; } if ( getRowIndex ( ) == rowIndex ) { return ; } FacesContext facesContext = getFacesContext ( ) ; if ( _initialDescendantFullComponentState != null ) { Map < String , Object > sm = saveFullDescendantComponentStates ( facesContext , null , getChildren ( ) . iterator ( ) , false ) ; if ( sm != null && ! sm . isEmpty ( ) ) { _rowDeltaStates . put ( getContainerClientId ( facesContext ) , sm ) ; } if ( getRowIndex ( ) != - 1 ) { _rowTransientStates . put ( getContainerClientId ( facesContext ) , saveTransientDescendantComponentStates ( facesContext , null , getChildren ( ) . iterator ( ) , false ) ) ; } } getStateHelper ( ) . put ( PropertyKeys . rowIndex , rowIndex ) ; DataModel localModel = getDataModel ( ) ; localModel . setRowIndex ( rowIndex ) ; if ( rowIndex == - 1 ) { setDataModel ( null ) ; } String var = getVar ( ) ; if ( var != null ) { Map < String , Object > requestMap = getFacesContext ( ) . getExternalContext ( ) . getRequestMap ( ) ; if ( rowIndex == - 1 ) { oldVar = requestMap . remove ( var ) ; } else if ( isRowAvailable ( ) ) { requestMap . put ( var , getRowData ( ) ) ; } else { requestMap . remove ( var ) ; if ( null != oldVar ) { requestMap . put ( var , oldVar ) ; oldVar = null ; } } } if ( _initialDescendantFullComponentState != null ) { Object rowState = _rowDeltaStates . get ( getContainerClientId ( facesContext ) ) ; if ( rowState == null ) { restoreFullDescendantComponentStates ( facesContext , getChildren ( ) . iterator ( ) , _initialDescendantFullComponentState , false ) ; } else { restoreFullDescendantComponentDeltaStates ( facesContext , getChildren ( ) . iterator ( ) , rowState , _initialDescendantFullComponentState , false ) ; } if ( getRowIndex ( ) == - 1 ) { restoreTransientDescendantComponentStates ( facesContext , getChildren ( ) . iterator ( ) , null , false ) ; } else { rowState = _rowTransientStates . get ( getContainerClientId ( facesContext ) ) ; if ( rowState == null ) { restoreTransientDescendantComponentStates ( facesContext , getChildren ( ) . iterator ( ) , null , false ) ; } else { restoreTransientDescendantComponentStates ( facesContext , getChildren ( ) . iterator ( ) , ( Map < String , Object > ) rowState , false ) ; } } } }
Row State preserved implementation is taken from Mojarra