public UIContext getRowContext ( final Object rowBean , final int rowIndex ) { RepeaterModel model = getOrCreateComponentModel ( ) ; Object rowId = getRowId ( rowBean ) ; if ( model . rowContextMap == null ) { model . rowContextMap = new HashMap <> ( ) ; } SubUIContext rowContext = model . rowContextMap . get ( rowId ) ; if ( rowContext == null ) { int seq = model . rowContextIdSequence ++ ; // Just for the first row, check rowId has implemented equals/hashcode. Assumes each row will use the same // row id class. if ( seq == 0 ) { try { if ( rowId . getClass ( ) != rowId . getClass ( ) . getMethod ( "equals" , Object . class ) . getDeclaringClass ( ) || rowId . getClass ( ) != rowId . getClass ( ) . getMethod ( "hashCode" ) . getDeclaringClass ( ) ) { LOG . warn ( "Row id class [" + rowId . getClass ( ) . getName ( ) + "] has not implemented equals or hashcode. This can cause errors when matching a row context. " + "Implement equals/hashcode on the row bean or refer to setRowIdBeanProperty method on WRepeater." ) ; } } catch ( Exception e ) { LOG . info ( "Error checking equals and hashcode implementation on the row id. " + e . getMessage ( ) , e ) ; } } // Get the row render id name (used in naming context for each row) String renderId = getRowIdName ( rowBean , rowId ) ; if ( renderId == null ) { // Just use the context id as the row naming context rowContext = new SubUIContext ( this , seq ) ; } else { // Check ID is properly formed // Must only contain letters, digits and or underscores Matcher matcher = ROW_ID_CONTEXT_NAME_PATTERN . matcher ( renderId ) ; if ( ! matcher . matches ( ) ) { throw new IllegalArgumentException ( "Row idName [" + renderId + "] must start with a letter and followed by letters, digits and or underscores." ) ; } rowContext = new SubUIContext ( this , seq , renderId ) ; } rowContext . setRowId ( rowId ) ; model . rowContextMap . put ( rowId , rowContext ) ; } rowContext . setRowIndex ( rowIndex ) ; // just incase it has changed return rowContext ; }
Retrieves the UIContext for a row .