idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
13,400
public static String getFirstAuthorizationGrant ( RamlAction action , RamlRoot document ) { List < String > grants = getAuthorizationGrants ( action , document ) ; if ( grants . isEmpty ( ) ) { return null ; } return grants . get ( 0 ) ; }
Returns authorization grant for provided action . It searches for authorization grants defined for provided action some of parent resources or the root of the document . If authorization grants found is a list - the method will return the first grant in the list .
13,401
public static List < String > removeDuplicates ( List < String > list ) { return list . stream ( ) . distinct ( ) . collect ( Collectors . toList ( ) ) ; }
Remove duplicates from provided list .
13,402
public static String getFormat ( TypeDeclaration param ) { if ( param == null ) { return null ; } if ( param instanceof NumberTypeDeclaration ) { return ( ( NumberTypeDeclaration ) param ) . format ( ) ; } if ( param instanceof DateTimeTypeDeclaration ) { return ( ( DateTimeTypeDeclaration ) param ) . format ( ) ; } return null ; }
IF it has a format defined this will return it
13,403
public static String getDescription ( TypeDeclaration type ) { if ( type == null || type . description ( ) == null ) { return null ; } else { return type . description ( ) . value ( ) ; } }
Safely get description from a type with null checks
13,404
public static String getExample ( TypeDeclaration type ) { if ( type == null || type . example ( ) == null ) { return null ; } else { return type . example ( ) . value ( ) ; } }
Safely get example from a type with null checks
13,405
public static String getDisplayName ( TypeDeclaration type ) { if ( type == null || type . displayName ( ) == null ) { return null ; } else { return type . displayName ( ) . value ( ) ; } }
Safely get Display name from a type with null checks
13,406
public static boolean isRequired ( TypeDeclaration type ) { if ( type == null || type . required ( ) == null ) { return true ; } else { return type . required ( ) ; } }
Safely get required from a type with null checks
13,407
public boolean isArray ( ) { if ( type == null ) { return false ; } return type . isArray ( ) || List . class . isAssignableFrom ( type ) || Set . class . isAssignableFrom ( type ) ; }
Quick check to see if this is an array type or not
13,408
public static String convertContentTypeToQualifier ( String contentType ) { if ( contentType . equals ( MediaType . APPLICATION_JSON_VALUE ) ) { return "AsJson" ; } if ( contentType . equals ( MediaType . APPLICATION_OCTET_STREAM_VALUE ) ) { return "AsBinary" ; } if ( contentType . equals ( MediaType . TEXT_PLAIN_VALUE ) || contentType . equals ( MediaType . TEXT_HTML_VALUE ) ) { return "AsText" ; } Matcher versionMatcher = CONTENT_TYPE_VERSION . matcher ( contentType ) ; if ( versionMatcher . find ( ) ) { String version = versionMatcher . group ( 1 ) ; if ( version != null ) { return StringUtils . capitalize ( version ) . replace ( "." , "_" ) ; } } int seperatorIndex = contentType . indexOf ( "/" ) ; if ( seperatorIndex != - 1 && seperatorIndex < contentType . length ( ) ) { String candidate = contentType . substring ( seperatorIndex + 1 ) . toLowerCase ( ) ; String out = "" ; if ( candidate . contains ( "json" ) ) { candidate = candidate . replace ( "json" , "" ) ; out += "AsJson" ; } candidate = StringUtils . deleteAny ( candidate , " ,.+=-'\"\\|~`#$%^&\n\t" ) ; if ( StringUtils . hasText ( candidate ) ) { out = StringUtils . capitalize ( candidate ) + out ; } return "_" + out ; } return "" ; }
Converts an http contentType into a qualifier that can be used within a Java method
13,409
public static List < String > extractUriParams ( String url ) { List < String > outParams = new ArrayList < > ( ) ; if ( StringUtils . hasText ( url ) ) { String [ ] split = StringUtils . split ( url , "/" ) ; for ( String part : split ) { int indexOfStart = part . indexOf ( "{" ) ; int indexOfEnd = part . indexOf ( "}" ) ; if ( indexOfStart != - 1 && indexOfEnd != - 1 && indexOfStart < indexOfEnd ) { outParams . add ( part . substring ( indexOfStart + 1 , indexOfEnd ) ) ; } } } return outParams ; }
Extracts a list of URI Parameters from a url
13,410
public static boolean isValidJavaClassName ( String input ) { if ( ! StringUtils . hasText ( input ) ) { return false ; } if ( ! Character . isJavaIdentifierStart ( input . charAt ( 0 ) ) ) { return false ; } if ( input . length ( ) > 1 ) { for ( int i = 1 ; i < input . length ( ) ; i ++ ) { if ( ! Character . isJavaIdentifierPart ( input . charAt ( i ) ) ) { return false ; } } } return true ; }
Utility method to check if a string can be used as a valid class name
13,411
public static String getAllResourcesNames ( String url , boolean singularize ) { StringBuilder stringBuilder = new StringBuilder ( ) ; if ( StringUtils . hasText ( url ) ) { String [ ] resources = SLASH . split ( url ) ; int lengthCounter = 0 ; for ( int i = resources . length - 1 ; i >= Config . getResourceTopLevelInClassNames ( ) + 1 ; -- i ) { if ( StringUtils . hasText ( resources [ i ] ) ) { String resourceName = getResourceName ( resources [ i ] , singularize ) ; if ( Config . isReverseOrderInClassNames ( ) ) { stringBuilder . append ( resourceName ) ; } else { stringBuilder . insert ( 0 , resourceName ) ; } ++ lengthCounter ; } if ( Config . getResourceDepthInClassNames ( ) > 0 && lengthCounter >= Config . getResourceDepthInClassNames ( ) ) { break ; } } } return stringBuilder . toString ( ) ; }
Attempts to infer the name of a resource from a resources s full URL .
13,412
public static String singularize ( String target ) { String result = Inflector . singularize ( target ) ; if ( ( target . endsWith ( "ss" ) ) && ( result . equals ( target . substring ( 0 , target . length ( ) - 1 ) ) ) ) { result = target ; } return result ; }
Singularises a string . uses underlying raml parser system
13,413
public static String cleanNameForJavaEnum ( String enumConstant ) { if ( ! StringUtils . hasText ( enumConstant ) ) { return enumConstant ; } List < String > nameGroups = new ArrayList < > ( asList ( splitByCharacterTypeCamelCase ( enumConstant ) ) ) ; nameGroups . removeIf ( s -> containsOnly ( s . replaceAll ( ILLEGAL_CHARACTER_REGEX , "_" ) , "_" ) ) ; String enumName = upperCase ( join ( nameGroups , "_" ) ) ; if ( isEmpty ( enumName ) ) { enumName = "_DEFAULT_" ; } else if ( Character . isDigit ( enumName . charAt ( 0 ) ) ) { enumName = "_" + enumName ; } return filterKeywords ( enumName ) ; }
Cleans a string with characters that are not valid as a java identifier enum
13,414
private static String convertActionTypeToIntent ( RamlActionType actionType , boolean isIdInPath ) { switch ( actionType ) { case DELETE : return "delete" ; case GET : return "get" ; case POST : if ( ! isIdInPath ) { return "create" ; } case PUT : return "update" ; case PATCH : return "modify" ; default : return "do" ; } }
Attempts to convert the Http Verb into a textual representation of Intent based on REST conventions
13,415
private void loadInfosFromSettings ( ScmProviderRepositoryWithHost repo ) { if ( username == null || password == null ) { String host = repo . getHost ( ) ; int port = repo . getPort ( ) ; if ( port > 0 ) { host += ":" + port ; } Server server = this . settings . getServer ( host ) ; if ( server != null ) { setPasswordIfNotEmpty ( repo , decrypt ( server . getPassword ( ) , host ) ) ; setUserIfNotEmpty ( repo , server . getUsername ( ) ) ; } } }
Load username password from settings .
13,416
protected InfoScmResult info ( ScmRepository repository , ScmFileSet fileSet ) throws ScmException { CommandParameters commandParameters = new CommandParameters ( ) ; if ( GitScmProviderRepository . PROTOCOL_GIT . equals ( scmManager . getProviderByRepository ( repository ) . getScmType ( ) ) && this . shortRevisionLength > 0 ) { getLog ( ) . info ( "ShortRevision tag detected. The value is '" + this . shortRevisionLength + "'." ) ; if ( shortRevisionLength >= 0 && shortRevisionLength < 4 ) { getLog ( ) . warn ( "shortRevision parameter less then 4. ShortRevisionLength is relaying on 'git rev-parese --short=LENGTH' command, accordingly to Git rev-parse specification the LENGTH value is miminum 4. " ) ; } commandParameters . setInt ( CommandParameter . SCM_SHORT_REVISION_LENGTH , this . shortRevisionLength ) ; } if ( ! StringUtils . isBlank ( scmTag ) && ! "HEAD" . equals ( scmTag ) ) { commandParameters . setScmVersion ( CommandParameter . SCM_VERSION , new ScmTag ( scmTag ) ) ; } return scmManager . getProviderByRepository ( repository ) . info ( repository . getProviderRepository ( ) , fileSet , commandParameters ) ; }
Get info from scm .
13,417
private String format ( Object [ ] arguments ) { Locale l = Locale . getDefault ( ) ; if ( locale != null ) { String [ ] parts = locale . split ( "_" , 3 ) ; if ( parts . length <= 1 ) { l = new Locale ( locale ) ; } else if ( parts . length == 2 ) { l = new Locale ( parts [ 0 ] , parts [ 1 ] ) ; } else { l = new Locale ( parts [ 0 ] , parts [ 1 ] , parts [ 2 ] ) ; } } return new MessageFormat ( format , l ) . format ( arguments ) ; }
Formats the given argument using the configured format template and locale .
13,418
public String getScmBranch ( ) throws MojoExecutionException { try { ScmRepository repository = getScmRepository ( ) ; ScmProvider provider = scmManager . getProviderByRepository ( repository ) ; if ( GitScmProviderRepository . PROTOCOL_GIT . equals ( provider . getScmType ( ) ) ) { ScmFileSet fileSet = new ScmFileSet ( scmDirectory ) ; return GitBranchCommand . getCurrentBranch ( getLogger ( ) , ( GitScmProviderRepository ) repository . getProviderRepository ( ) , fileSet ) ; } else if ( provider instanceof HgScmProvider ) { HgOutputConsumer consumer = new HgOutputConsumer ( getLogger ( ) ) ; ScmResult result = HgUtils . execute ( consumer , logger , scmDirectory , new String [ ] { "id" , "-b" } ) ; checkResult ( result ) ; if ( StringUtils . isNotEmpty ( consumer . getOutput ( ) ) ) { return consumer . getOutput ( ) ; } } } catch ( ScmException e ) { getLog ( ) . warn ( "Cannot get the branch information from the git repository: \n" + e . getLocalizedMessage ( ) ) ; } return getScmBranchFromUrl ( ) ; }
Get the branch info for this revision from the repository . For svn it is in svn info .
13,419
public String getRevision ( ) throws MojoExecutionException { if ( format != null && ! useScm ) { return revision ; } useScm = false ; try { return this . getScmRevision ( ) ; } catch ( ScmException e ) { if ( ! StringUtils . isEmpty ( revisionOnScmFailure ) ) { getLog ( ) . warn ( "Cannot get the revision information from the scm repository, proceeding with " + "revision of " + revisionOnScmFailure + " : \n" + e . getLocalizedMessage ( ) ) ; setDoCheck ( false ) ; setDoUpdate ( false ) ; return revisionOnScmFailure ; } throw new MojoExecutionException ( "Cannot get the revision information from the scm repository : \n" + e . getLocalizedMessage ( ) , e ) ; } }
Get the revision info from the repository . For svn it is svn info
13,420
public CreateIssueParams estimatedHours ( BigDecimal estimatedHours ) { if ( estimatedHours == null ) { parameters . add ( new NameValuePair ( "estimatedHours" , "" ) ) ; } else { parameters . add ( new NameValuePair ( "estimatedHours" , estimatedHours . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) . toPlainString ( ) ) ) ; } return this ; }
Sets the issue estimate hours .
13,421
public CreateIssueParams actualHours ( BigDecimal actualHours ) { if ( actualHours == null ) { parameters . add ( new NameValuePair ( "actualHours" , "" ) ) ; } else { parameters . add ( new NameValuePair ( "actualHours" , actualHours . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) . toPlainString ( ) ) ) ; } return this ; }
Sets the issue actual hours .
13,422
public CreateIssueParams milestoneIds ( List milestoneIds ) { for ( Object milestoneId : milestoneIds ) { parameters . add ( new NameValuePair ( "milestoneId[]" , milestoneId . toString ( ) ) ) ; } return this ; }
Sets the issue milestones .
13,423
public CreateIssueParams notifiedUserIds ( List notifiedUserIds ) { for ( Object notifiedUserId : notifiedUserIds ) { parameters . add ( new NameValuePair ( "notifiedUserId[]" , notifiedUserId . toString ( ) ) ) ; } return this ; }
Sets the issue notified users .
13,424
public CreateIssueParams textCustomFields ( List < CustomFiledValue > customFieldValueList ) { for ( CustomFiledValue customFiledValue : customFieldValueList ) { textCustomField ( customFiledValue ) ; } return this ; }
Sets the text type custom field with Map .
13,425
public CreateIssueParams multipleListCustomField ( CustomFiledItems customFiledItems ) { for ( Object id : customFiledItems . getCustomFieldItemIds ( ) ) { parameters . add ( new NameValuePair ( "customField_" + customFiledItems . getCustomFieldId ( ) , id . toString ( ) ) ) ; } return this ; }
Sets the multiple list type custom field .
13,426
public CreateIssueParams multipleListCustomFields ( List < CustomFiledItems > customFiledItemsList ) { for ( CustomFiledItems customFiledItems : customFiledItemsList ) { multipleListCustomField ( customFiledItems ) ; } return this ; }
Sets the multiple list type custom field with Map .
13,427
public String getSharedFileEndpoint ( Object projectIdOrKey , Object sharedFileId ) throws BacklogException { return buildEndpoint ( "projects/" + projectIdOrKey + "/files/" + sharedFileId ) ; }
Returns the endpoint of shared file .
13,428
public String getWikiAttachmentEndpoint ( Object wikiId , Object attachmentId ) throws BacklogException { return buildEndpoint ( "wikis/" + wikiId + "/attachments/" + attachmentId ) ; }
Returns the endpoint of Wiki page s attachment file .
13,429
public CreateWebhookParams description ( String description ) { String value = ( description == null ) ? "" : description ; parameters . add ( new NameValuePair ( "description" , value ) ) ; return this ; }
Sets the description parameter .
13,430
public AddPullRequestCommentParams notifiedUserIds ( List < Long > notifiedUserIds ) { for ( Long notifiedUserId : notifiedUserIds ) { parameters . add ( new NameValuePair ( "notifiedUserId[]" , String . valueOf ( notifiedUserId ) ) ) ; } return this ; }
Sets the notified users .
13,431
public UpdatePullRequestParams notifiedUserIds ( List < Long > notifiedUserIds ) { for ( Long notifiedUserId : notifiedUserIds ) { parameters . add ( new NameValuePair ( "notifiedUserId[]" , notifiedUserId . toString ( ) ) ) ; } return this ; }
Sets the pull request notified users .
13,432
public UpdatePullRequestParams attachmentIds ( List < Long > attachmentIds ) { for ( Long attachmentId : attachmentIds ) { parameters . add ( new NameValuePair ( "attachmentId[]" , attachmentId . toString ( ) ) ) ; } return this ; }
Sets the pull request attachment files .
13,433
public void encodeEnd ( final FacesContext context , final UIComponent component ) throws IOException { final ResponseWriter responseWriter = context . getResponseWriter ( ) ; final Sheet sheet = ( Sheet ) component ; sheet . updateColumnMappings ( ) ; sheet . sortAndFilter ( ) ; encodeMarkup ( context , sheet , responseWriter ) ; encodeScript ( context , sheet , responseWriter ) ; }
Encodes the Sheet component
13,434
protected void encodeMarkup ( final FacesContext context , final Sheet sheet , final ResponseWriter responseWriter ) throws IOException { final String styleClass = sheet . getStyleClass ( ) ; final String clientId = sheet . getClientId ( context ) ; final Integer width = sheet . getWidth ( ) ; final Integer height = sheet . getHeight ( ) ; String style = sheet . getStyle ( ) ; responseWriter . startElement ( "div" , null ) ; responseWriter . writeAttribute ( "id" , clientId , "id" ) ; responseWriter . writeAttribute ( "name" , clientId , "clientId" ) ; String divclass = "ui-handsontable ui-widget" ; if ( styleClass != null ) { divclass = divclass + " " + styleClass ; } if ( ! sheet . isValid ( ) ) { divclass = divclass + " ui-state-error" ; } responseWriter . writeAttribute ( "class" , divclass , "styleClass" ) ; if ( width != null ) { responseWriter . writeAttribute ( "style" , "width: " + width + "px;" , null ) ; } encodeHiddenInputs ( responseWriter , sheet , clientId ) ; encodeFilterValues ( context , responseWriter , sheet , clientId ) ; encodeHeader ( context , responseWriter , sheet ) ; responseWriter . startElement ( "div" , null ) ; responseWriter . writeAttribute ( "id" , clientId + "_tbl" , "id" ) ; responseWriter . writeAttribute ( "name" , clientId + "_tbl" , "clientId" ) ; responseWriter . writeAttribute ( "class" , "handsontable-inner" , "styleClass" ) ; if ( style == null ) { style = Constants . EMPTY_STRING ; } if ( width != null ) { style = style + "width: " + width + "px;" ; } if ( height != null ) { style = style + "height: " + height + "px;" ; } else { style = style + "height: 100%;" ; } if ( style . length ( ) > 0 ) { responseWriter . writeAttribute ( "style" , style , null ) ; } responseWriter . endElement ( "div" ) ; encodeFooter ( context , responseWriter , sheet ) ; responseWriter . endElement ( "div" ) ; }
Encodes the HTML markup for the sheet .
13,435
protected void encodeOptionalAttr ( final WidgetBuilder wb , final String attrName , final String value ) throws IOException { if ( value != null ) { wb . attr ( attrName , value ) ; } }
Encodes an optional attribute to the widget builder specified .
13,436
protected void encodeInvalidData ( final FacesContext context , final Sheet sheet , final WidgetBuilder wb ) throws IOException { wb . attr ( "errors" , sheet . getInvalidDataValue ( ) ) ; }
Encodes the necessary JS to render invalid data .
13,437
protected void encodeColHeaders ( final FacesContext context , final Sheet sheet , final WidgetBuilder wb ) throws IOException { final JavascriptVarBuilder vb = new JavascriptVarBuilder ( null , false ) ; for ( final SheetColumn column : sheet . getColumns ( ) ) { if ( ! column . isRendered ( ) ) { continue ; } vb . appendArrayValue ( column . getHeaderText ( ) , true ) ; } wb . nativeAttr ( "colHeaders" , vb . closeVar ( ) . toString ( ) ) ; }
Encode the column headers
13,438
protected void encodeData ( final FacesContext context , final Sheet sheet , final WidgetBuilder wb ) throws IOException { final JavascriptVarBuilder jsData = new JavascriptVarBuilder ( null , false ) ; final JavascriptVarBuilder jsRowKeys = new JavascriptVarBuilder ( null , false ) ; final JavascriptVarBuilder jsStyle = new JavascriptVarBuilder ( null , true ) ; final JavascriptVarBuilder jsRowStyle = new JavascriptVarBuilder ( null , false ) ; final JavascriptVarBuilder jsReadOnly = new JavascriptVarBuilder ( null , true ) ; final JavascriptVarBuilder jsRowHeaders = new JavascriptVarBuilder ( null , false ) ; final boolean isCustomHeader = sheet . getRowHeaderValueExpression ( ) != null ; final List < Object > values = sheet . getSortedValues ( ) ; int row = 0 ; for ( final Object value : values ) { context . getExternalContext ( ) . getRequestMap ( ) . put ( sheet . getVar ( ) , value ) ; final String rowKey = sheet . getRowKeyValueAsString ( context ) ; jsRowKeys . appendArrayValue ( rowKey , true ) ; encodeRow ( context , rowKey , jsData , jsRowStyle , jsStyle , jsReadOnly , sheet , row ) ; if ( sheet . isShowRowHeaders ( ) && isCustomHeader ) { final String rowHeader = sheet . getRowHeaderValueAsString ( context ) ; jsRowHeaders . appendArrayValue ( rowHeader , true ) ; } row ++ ; } sheet . setRowVar ( context , null ) ; wb . nativeAttr ( "data" , jsData . closeVar ( ) . toString ( ) ) ; wb . nativeAttr ( "styles" , jsStyle . closeVar ( ) . toString ( ) ) ; wb . nativeAttr ( "rowStyles" , jsRowStyle . closeVar ( ) . toString ( ) ) ; wb . nativeAttr ( "readOnlyCells" , jsReadOnly . closeVar ( ) . toString ( ) ) ; wb . nativeAttr ( "rowKeys" , jsRowKeys . closeVar ( ) . toString ( ) ) ; if ( ! isCustomHeader ) { wb . nativeAttr ( "rowHeaders" , sheet . isShowRowHeaders ( ) . toString ( ) ) ; } else { wb . nativeAttr ( "rowHeaders" , jsRowHeaders . closeVar ( ) . toString ( ) ) ; } }
Encode the row data . Builds row data style data and read only object .
13,439
protected JavascriptVarBuilder encodeRow ( final FacesContext context , final String rowKey , final JavascriptVarBuilder jsData , final JavascriptVarBuilder jsRowStyle , final JavascriptVarBuilder jsStyle , final JavascriptVarBuilder jsReadOnly , final Sheet sheet , final int rowIndex ) throws IOException { final String rowStyleClass = sheet . getRowStyleClass ( ) ; if ( rowStyleClass == null ) { jsRowStyle . appendArrayValue ( "null" , false ) ; } else { jsRowStyle . appendArrayValue ( rowStyleClass , true ) ; } final JavascriptVarBuilder jsRow = new JavascriptVarBuilder ( null , false ) ; int renderCol = 0 ; for ( int col = 0 ; col < sheet . getColumns ( ) . size ( ) ; col ++ ) { final SheetColumn column = sheet . getColumns ( ) . get ( col ) ; if ( ! column . isRendered ( ) ) { continue ; } final String value = sheet . getRenderValueForCell ( context , rowKey , col ) ; jsRow . appendArrayValue ( value , true ) ; final String styleClass = column . getStyleClass ( ) ; if ( styleClass != null ) { jsStyle . appendRowColProperty ( rowIndex , renderCol , styleClass , true ) ; } final boolean readOnly = column . isReadonlyCell ( ) ; if ( readOnly ) { jsReadOnly . appendRowColProperty ( rowIndex , renderCol , "true" , true ) ; } renderCol ++ ; } jsData . appendArrayValue ( jsRow . closeVar ( ) . toString ( ) , false ) ; return jsData ; }
Encode a single row .
13,440
private void encodeHiddenInputs ( final ResponseWriter responseWriter , final Sheet sheet , final String clientId ) throws IOException { responseWriter . startElement ( "input" , null ) ; responseWriter . writeAttribute ( "id" , clientId + "_input" , "id" ) ; responseWriter . writeAttribute ( "name" , clientId + "_input" , "name" ) ; responseWriter . writeAttribute ( "type" , "hidden" , null ) ; responseWriter . writeAttribute ( "value" , "" , null ) ; responseWriter . endElement ( "input" ) ; responseWriter . startElement ( "input" , null ) ; responseWriter . writeAttribute ( "id" , clientId + "_focus" , "id" ) ; responseWriter . writeAttribute ( "name" , clientId + "_focus" , "name" ) ; responseWriter . writeAttribute ( "type" , "hidden" , null ) ; if ( sheet . getFocusId ( ) == null ) { responseWriter . writeAttribute ( "value" , "" , null ) ; } else { responseWriter . writeAttribute ( "value" , sheet . getFocusId ( ) , null ) ; } responseWriter . endElement ( "input" ) ; responseWriter . startElement ( "input" , null ) ; responseWriter . writeAttribute ( "id" , clientId + "_selection" , "id" ) ; responseWriter . writeAttribute ( "name" , clientId + "_selection" , "name" ) ; responseWriter . writeAttribute ( "type" , "hidden" , null ) ; if ( sheet . getSelection ( ) == null ) { responseWriter . writeAttribute ( "value" , "" , null ) ; } else { responseWriter . writeAttribute ( "value" , sheet . getSelection ( ) , null ) ; } responseWriter . endElement ( "input" ) ; final int sortCol = sheet . getSortColRenderIndex ( ) ; responseWriter . startElement ( "input" , null ) ; responseWriter . writeAttribute ( "id" , clientId + "_sortby" , "id" ) ; responseWriter . writeAttribute ( "name" , clientId + "_sortby" , "name" ) ; responseWriter . writeAttribute ( "type" , "hidden" , null ) ; responseWriter . writeAttribute ( "value" , sortCol , null ) ; responseWriter . endElement ( "input" ) ; responseWriter . startElement ( "input" , null ) ; responseWriter . writeAttribute ( "id" , clientId + "_sortorder" , "id" ) ; responseWriter . writeAttribute ( "name" , clientId + "_sortorder" , "name" ) ; responseWriter . writeAttribute ( "type" , "hidden" , null ) ; responseWriter . writeAttribute ( "value" , sheet . getSortOrder ( ) . toLowerCase ( ) , null ) ; responseWriter . endElement ( "input" ) ; }
Encode hidden input fields
13,441
private void encodeFooter ( final FacesContext context , final ResponseWriter responseWriter , final Sheet sheet ) throws IOException { final UIComponent footer = sheet . getFacet ( "footer" ) ; if ( footer != null ) { responseWriter . startElement ( "div" , null ) ; responseWriter . writeAttribute ( "class" , "ui-datatable-footer ui-widget-header ui-corner-bottom" , null ) ; footer . encodeAll ( context ) ; responseWriter . endElement ( "div" ) ; } }
Encode the sheet footer
13,442
private void encodeHeader ( final FacesContext context , final ResponseWriter responseWriter , final Sheet sheet ) throws IOException { final UIComponent header = sheet . getFacet ( "header" ) ; if ( header != null ) { responseWriter . startElement ( "div" , null ) ; responseWriter . writeAttribute ( "class" , "ui-datatable-header ui-widget-header ui-corner-top" , null ) ; header . encodeAll ( context ) ; responseWriter . endElement ( "div" ) ; } }
Encode the Sheet header
13,443
protected void encodeFilterValues ( final FacesContext context , final ResponseWriter responseWriter , final Sheet sheet , final String clientId ) throws IOException { int renderCol = 0 ; for ( final SheetColumn column : sheet . getColumns ( ) ) { if ( ! column . isRendered ( ) ) { continue ; } if ( column . getValueExpression ( "filterBy" ) != null ) { responseWriter . startElement ( "input" , null ) ; responseWriter . writeAttribute ( "id" , clientId + "_filter_" + renderCol , "id" ) ; responseWriter . writeAttribute ( "name" , clientId + "_filter_" + renderCol , "name" ) ; responseWriter . writeAttribute ( "type" , "hidden" , null ) ; responseWriter . writeAttribute ( "value" , column . getFilterValue ( ) , null ) ; responseWriter . endElement ( "input" ) ; } renderCol ++ ; } }
Encodes the filter values .
13,444
protected void encodeSortVar ( final FacesContext context , final Sheet sheet , final WidgetBuilder wb ) throws IOException { final JavascriptVarBuilder vb = new JavascriptVarBuilder ( null , false ) ; for ( final SheetColumn column : sheet . getColumns ( ) ) { if ( ! column . isRendered ( ) ) { continue ; } if ( column . getValueExpression ( "sortBy" ) == null ) { vb . appendArrayValue ( "false" , false ) ; } else { vb . appendArrayValue ( "true" , false ) ; } } wb . nativeAttr ( "sortable" , vb . closeVar ( ) . toString ( ) ) ; }
Encodes a javascript sort var that informs the col header event of the column s sorting options . The var is an array of boolean indicating whether or not the column is sortable .
13,445
protected void decodeFilters ( final FacesContext context , final Sheet sheet , final Map < String , String > params , final String clientId ) { int renderCol = 0 ; for ( final SheetColumn column : sheet . getColumns ( ) ) { if ( ! column . isRendered ( ) ) { continue ; } if ( column . getValueExpression ( "filterBy" ) != null ) { final String value = params . get ( clientId + "_filter_" + renderCol ) ; column . setFilterValue ( value ) ; } renderCol ++ ; } }
Decodes the filter values
13,446
private void decodeSelection ( final FacesContext context , final Sheet sheet , final String jsonSelection ) { if ( LangUtils . isValueBlank ( jsonSelection ) ) { return ; } try { final JSONArray array = new JSONArray ( jsonSelection ) ; sheet . setSelectedRow ( array . getInt ( 0 ) ) ; sheet . setSelectedColumn ( sheet . getMappedColumn ( array . getInt ( 1 ) ) ) ; sheet . setSelectedLastRow ( array . getInt ( 2 ) ) ; sheet . setSelectedLastColumn ( array . getInt ( 3 ) ) ; sheet . setSelection ( jsonSelection ) ; } catch ( final JSONException e ) { throw new FacesException ( "Failed parsing Ajax JSON message for cell selection event:" + e . getMessage ( ) , e ) ; } }
Decodes the user Selection JSON data
13,447
private void decodeSubmittedValues ( final FacesContext context , final Sheet sheet , final String jsonData ) { if ( LangUtils . isValueBlank ( jsonData ) ) { return ; } try { final JSONObject obj = new JSONObject ( jsonData ) ; final Iterator < String > keys = obj . keys ( ) ; while ( keys . hasNext ( ) ) { final String key = keys . next ( ) ; final JSONArray update = obj . getJSONArray ( key ) ; if ( update . isNull ( 4 ) ) { continue ; } final String rowKey = update . getString ( 4 ) ; final int col = sheet . getMappedColumn ( update . getInt ( 1 ) ) ; final String newValue = String . valueOf ( update . get ( 3 ) ) ; sheet . setSubmittedValue ( context , rowKey , col , newValue ) ; } } catch ( final JSONException ex ) { throw new FacesException ( "Failed parsing Ajax JSON message for cell change event:" + ex . getMessage ( ) , ex ) ; } }
Converts the JSON data received from the in the request params into our sumitted values map . The map is cleared first .
13,448
public RequestParameterBuilder paramJson ( String name , Object value ) throws UnsupportedEncodingException { return paramJson ( name , value , null ) ; }
Adds a request parameter to the URL without specifying a data type of the given parameter value . Parameter s value is converted to JSON notation when adding . Furthermore it will be encoded according to the acquired encoding .
13,449
public RequestParameterBuilder paramJson ( String name , Object value , String type ) throws UnsupportedEncodingException { String encodedJsonValue = encodeJson ( value , type ) ; if ( added || originalUrl . contains ( "?" ) ) { buffer . append ( "&" ) ; } else { buffer . append ( "?" ) ; } buffer . append ( name ) ; buffer . append ( "=" ) ; buffer . append ( encodedJsonValue ) ; added = true ; return this ; }
Adds a request parameter to the URL with specifying a data type of the given parameter value . Data type is sometimes required especially for Java generic types because type information is erased at runtime and the conversion to JSON will not work properly . Parameter s value is converted to JSON notation when adding . Furthermore it will be encoded according to the acquired encoding .
13,450
public String encodeJson ( Object value , String type ) throws UnsupportedEncodingException { jsonConverter . setType ( type ) ; String jsonValue ; if ( value == null ) { jsonValue = "null" ; } else { jsonValue = jsonConverter . getAsString ( null , null , value ) ; } return URLEncoder . encode ( jsonValue , encoding ) ; }
Convertes give value to JSON and encodes the converted value with a proper encoding . Data type is sometimes required especially for Java generic types because type information is erased at runtime and the conversion to JSON will not work properly .
13,451
public String build ( ) { String url = buffer . toString ( ) ; if ( url . length ( ) > 2083 ) { LOG . warning ( "URL " + url + " is longer than 2083 chars (" + buffer . length ( ) + "). It may not work properly in old IE versions." ) ; } return url ; }
Builds the end result .
13,452
public RequestParameterBuilder reset ( ) { buffer = new StringBuilder ( originalUrl ) ; jsonConverter . setType ( null ) ; added = false ; return this ; }
Resets the internal state in order to be reused .
13,453
public DynaFormControl addControl ( final Object data , final int colspan , final int rowspan ) { return addControl ( data , DynaFormControl . DEFAULT_TYPE , colspan , rowspan ) ; }
Adds control with given data default type colspan and rowspan .
13,454
public DynaFormControl addControl ( final Object data , final String type , final int colspan , final int rowspan ) { final DynaFormControl dynaFormControl = new DynaFormControl ( data , type , colspan , rowspan , row , elements . size ( ) + 1 , dynaFormModel . getControls ( ) . size ( ) + 1 , extended ) ; elements . add ( dynaFormControl ) ; dynaFormModel . getControls ( ) . add ( dynaFormControl ) ; totalColspan = totalColspan + colspan ; return dynaFormControl ; }
Adds control with given data type colspan and rowspan .
13,455
public DynaFormLabel addLabel ( final String value , final int colspan , final int rowspan ) { return addLabel ( value , true , colspan , rowspan ) ; }
Adds a label with given text colspan and rowspan .
13,456
public DynaFormLabel addLabel ( final String value , final boolean escape , final int colspan , final int rowspan ) { final DynaFormLabel dynaFormLabel = new DynaFormLabel ( value , escape , colspan , rowspan , row , elements . size ( ) + 1 , extended ) ; elements . add ( dynaFormLabel ) ; dynaFormModel . getLabels ( ) . add ( dynaFormLabel ) ; totalColspan = totalColspan + colspan ; return dynaFormLabel ; }
Adds a label with given text escape flag colspan and rowspan .
13,457
private void getColumns ( final UIComponent parent ) { for ( final UIComponent child : parent . getChildren ( ) ) { if ( child instanceof SheetColumn ) { columns . add ( ( SheetColumn ) child ) ; } } }
Grabs the UIColumn children for the parent specified .
13,458
public void reset ( ) { resetSubmitted ( ) ; resetSort ( ) ; resetInvalidUpdates ( ) ; localValues . clear ( ) ; for ( final SheetColumn c : getColumns ( ) ) { c . setFilterValue ( null ) ; } }
Resets all filters sorting and submitted values .
13,459
public void setSubmittedValue ( final FacesContext context , final String rowKey , final int col , final String value ) { submittedValues . put ( new SheetRowColIndex ( rowKey , col ) , value ) ; }
Updates a submitted value .
13,460
public String getSubmittedValue ( final String rowKey , final int col ) { return submittedValues . get ( new SheetRowColIndex ( rowKey , col ) ) ; }
Retrieves the submitted value for the row and col .
13,461
public void setLocalValue ( final String rowKey , final int col , final Object value ) { localValues . put ( new SheetRowColIndex ( rowKey , col ) , value ) ; }
Updates a local value .
13,462
public Object getLocalValue ( final String rowKey , final int col ) { return localValues . get ( new SheetRowColIndex ( rowKey , col ) ) ; }
Retrieves the submitted value for the rowKey and col .
13,463
public void setRowVar ( final FacesContext context , final String rowKey ) { if ( context == null ) { return ; } if ( rowKey == null ) { context . getExternalContext ( ) . getRequestMap ( ) . remove ( getVar ( ) ) ; } else { final Object value = getRowMap ( ) . get ( rowKey ) ; context . getExternalContext ( ) . getRequestMap ( ) . put ( getVar ( ) , value ) ; } }
Updates the row var for iterations over the list . The var value will be updated to the value for the specified rowKey .
13,464
public Object getValueForCell ( final FacesContext context , final String rowKey , final int col ) { final SheetRowColIndex index = new SheetRowColIndex ( rowKey , col ) ; if ( localValues . containsKey ( index ) ) { return localValues . get ( index ) ; } setRowVar ( context , rowKey ) ; final SheetColumn column = getColumns ( ) . get ( col ) ; return column . getValueExpression ( "value" ) . getValue ( context . getELContext ( ) ) ; }
Gets the object value of the row and col specified . If a local value exists that is returned otherwise the actual value is return .
13,465
public String getRenderValueForCell ( final FacesContext context , final String rowKey , final int col ) { final SheetRowColIndex index = new SheetRowColIndex ( rowKey , col ) ; if ( submittedValues . containsKey ( index ) ) { return submittedValues . get ( index ) ; } final Object value = getValueForCell ( context , rowKey , col ) ; if ( value == null ) { return null ; } final SheetColumn column = getColumns ( ) . get ( col ) ; final Converter converter = ComponentUtils . getConverter ( context , column ) ; if ( converter == null ) { return value . toString ( ) ; } else { return converter . getAsString ( context , this , value ) ; } }
Gets the render string for the value the given cell . Applys the available converters to convert the value .
13,466
protected String getRowHeaderValueAsString ( final FacesContext context ) { final ValueExpression veRowHeader = getRowHeaderValueExpression ( ) ; final Object value = veRowHeader . getValue ( context . getELContext ( ) ) ; if ( value == null ) { return Constants . EMPTY_STRING ; } else { return value . toString ( ) ; } }
Gets the row header text value as a string for use in javascript
13,467
public List < Object > getSortedValues ( ) { List < Object > filtered = getFilteredValue ( ) ; if ( filtered == null || filtered . isEmpty ( ) ) { filtered = sortAndFilter ( ) ; } return filtered ; }
The sorted list of values .
13,468
public int getSortColRenderIndex ( ) { final ValueExpression veSortBy = getValueExpression ( PropertyKeys . sortBy . name ( ) ) ; if ( veSortBy == null ) { return - 1 ; } final String sortByExp = veSortBy . getExpressionString ( ) ; int colIdx = 0 ; for ( final SheetColumn column : getColumns ( ) ) { if ( ! column . isRendered ( ) ) { continue ; } final ValueExpression veCol = column . getValueExpression ( PropertyKeys . sortBy . name ( ) ) ; if ( veCol != null ) { if ( veCol . getExpressionString ( ) . equals ( sortByExp ) ) { return colIdx ; } } colIdx ++ ; } return - 1 ; }
Gets the rendered col index of the column corresponding to the current sortBy . This is used to keep track of the current sort column in the page .
13,469
public List < Object > sortAndFilter ( ) { final List filteredList = getFilteredValue ( ) ; filteredList . clear ( ) ; rowMap = new HashMap < > ( ) ; rowNumbers = new HashMap < > ( ) ; final Collection < ? > values = ( Collection < ? > ) getValue ( ) ; if ( values == null || values . isEmpty ( ) ) { return filteredList ; } remapRows ( ) ; boolean filters = false ; for ( final SheetColumn col : getColumns ( ) ) { if ( ! LangUtils . isValueBlank ( col . getFilterValue ( ) ) ) { filters = true ; break ; } } final FacesContext context = FacesContext . getCurrentInstance ( ) ; final Map < String , Object > requestMap = context . getExternalContext ( ) . getRequestMap ( ) ; final String var = getVar ( ) ; if ( filters ) { for ( final Object obj : values ) { requestMap . put ( var , obj ) ; if ( matchesFilter ( obj ) ) { filteredList . add ( obj ) ; } } } else { filteredList . addAll ( values ) ; } final ValueExpression veSortBy = getValueExpression ( PropertyKeys . sortBy . name ( ) ) ; if ( veSortBy != null ) { Collections . sort ( filteredList , new BeanPropertyComparator ( veSortBy , var , convertSortOrder ( ) , null , isCaseSensitiveSort ( ) , Locale . ENGLISH , getNullSortOrder ( ) ) ) ; } remapFilteredList ( filteredList ) ; return filteredList ; }
Sorts and filters the data
13,470
protected Object getRowKeyValue ( final FacesContext context ) { final ValueExpression veRowKey = getValueExpression ( PropertyKeys . rowKey . name ( ) ) ; if ( veRowKey == null ) { throw new RuntimeException ( "RowKey required on sheet!" ) ; } final Object value = veRowKey . getValue ( context . getELContext ( ) ) ; if ( value == null ) { throw new RuntimeException ( "RowKey must resolve to non-null value for updates to work properly" ) ; } return value ; }
Gets the rowKey for the current row
13,471
protected String getRowKeyValueAsString ( final Object key ) { final String result = key . toString ( ) ; return "r_" + StringUtils . deleteWhitespace ( result ) ; }
Gets the row key value as a String suitable for use in javascript rendering .
13,472
protected SortOrder convertSortOrder ( ) { final String sortOrder = getSortOrder ( ) ; if ( sortOrder == null ) { return SortOrder . UNSORTED ; } else { final SortOrder result = SortOrder . valueOf ( sortOrder . toUpperCase ( Locale . ENGLISH ) ) ; return result ; } }
Convert to PF SortOrder enum since we are leveraging PF sorting code .
13,473
public void validate ( final FacesContext context ) { final Iterator < Entry < SheetRowColIndex , String > > entries = submittedValues . entrySet ( ) . iterator ( ) ; final boolean hadBadUpdates = ! getInvalidUpdates ( ) . isEmpty ( ) ; getInvalidUpdates ( ) . clear ( ) ; while ( entries . hasNext ( ) ) { final Entry < SheetRowColIndex , String > entry = entries . next ( ) ; final SheetColumn column = getColumns ( ) . get ( entry . getKey ( ) . getColIndex ( ) ) ; final String newValue = entry . getValue ( ) ; final String rowKey = entry . getKey ( ) . getRowKey ( ) ; final int col = entry . getKey ( ) . getColIndex ( ) ; setRowVar ( context , rowKey ) ; final Converter converter = ComponentUtils . getConverter ( context , column ) ; Object newValueObj = newValue ; if ( converter != null ) { try { newValueObj = converter . getAsObject ( context , this , newValue ) ; } catch ( final ConverterException e ) { setValid ( false ) ; FacesMessage message = e . getFacesMessage ( ) ; if ( message == null ) { message = new FacesMessage ( FacesMessage . SEVERITY_ERROR , e . getMessage ( ) , e . getMessage ( ) ) ; } context . addMessage ( this . getClientId ( context ) , message ) ; final String messageText = message . getDetail ( ) ; getInvalidUpdates ( ) . add ( new SheetInvalidUpdate ( getRowKeyValue ( context ) , col , column , newValue , messageText ) ) ; continue ; } } setLocalValue ( rowKey , col , newValueObj ) ; column . setValue ( newValueObj ) ; try { column . validate ( context ) ; } finally { column . resetValue ( ) ; } entries . remove ( ) ; } setRowVar ( context , null ) ; final boolean newBadUpdates = ! getInvalidUpdates ( ) . isEmpty ( ) ; final String errorMessage = getErrorMessage ( ) ; if ( hadBadUpdates || newBadUpdates ) { if ( context . getPartialViewContext ( ) . isPartialRequest ( ) ) { renderBadUpdateScript ( context ) ; } } if ( newBadUpdates && errorMessage != null ) { final FacesMessage message = new FacesMessage ( FacesMessage . SEVERITY_ERROR , errorMessage , errorMessage ) ; context . addMessage ( null , message ) ; } }
Converts each submitted value into a local value and stores it back in the hash . If all values convert without error then the component is valid and we can proceed to the processUpdates .
13,474
public Object saveState ( final FacesContext context ) { final Object values [ ] = new Object [ 8 ] ; values [ 0 ] = super . saveState ( context ) ; values [ 1 ] = submittedValues ; values [ 2 ] = localValues ; values [ 3 ] = invalidUpdates ; values [ 4 ] = columnMapping ; values [ 5 ] = getFilteredValue ( ) ; values [ 6 ] = rowMap ; values [ 7 ] = rowNumbers ; return values ; }
Saves the state of the submitted and local values and the bad updates .
13,475
public void restoreState ( final FacesContext context , final Object state ) { if ( state == null ) { return ; } final Object values [ ] = ( Object [ ] ) state ; super . restoreState ( context , values [ 0 ] ) ; final Object restoredSubmittedValues = values [ 1 ] ; final Object restoredLocalValues = values [ 2 ] ; final Object restoredInvalidUpdates = values [ 3 ] ; final Object restoredColMappings = values [ 4 ] ; final Object restoredSortedList = values [ 5 ] ; final Object restoredRowMap = values [ 6 ] ; final Object restoredRowNumbers = values [ 7 ] ; if ( restoredSubmittedValues == null ) { submittedValues . clear ( ) ; } else { submittedValues = ( Map < SheetRowColIndex , String > ) restoredSubmittedValues ; } if ( restoredLocalValues == null ) { localValues . clear ( ) ; } else { localValues = ( Map < SheetRowColIndex , Object > ) restoredLocalValues ; } if ( restoredInvalidUpdates == null ) { getInvalidUpdates ( ) . clear ( ) ; } else { invalidUpdates = ( List < SheetInvalidUpdate > ) restoredInvalidUpdates ; } if ( restoredColMappings == null ) { columnMapping = null ; } else { columnMapping = ( Map < Integer , Integer > ) restoredColMappings ; } if ( restoredSortedList == null ) { getFilteredValue ( ) . clear ( ) ; } else { setFilteredValue ( ( List < Object > ) restoredSortedList ) ; } if ( restoredRowMap == null ) { rowMap = null ; } else { rowMap = ( Map < String , Object > ) restoredRowMap ; } if ( restoredRowNumbers == null ) { rowNumbers = null ; } else { rowNumbers = ( Map < String , Integer > ) restoredRowNumbers ; } }
Restores the state for the submitted local and bad values .
13,476
public int getMappedColumn ( final int renderCol ) { if ( columnMapping == null || renderCol == - 1 ) { return renderCol ; } else { final Integer result = columnMapping . get ( renderCol ) ; if ( result == null ) { throw new IllegalArgumentException ( "Invalid index " + renderCol ) ; } return result ; } }
Maps the rendered column index to the real column index .
13,477
public int getRenderIndexFromRealIdx ( final int realIdx ) { if ( columnMapping == null || realIdx == - 1 ) { return realIdx ; } for ( final Entry < Integer , Integer > entry : columnMapping . entrySet ( ) ) { if ( entry . getValue ( ) . equals ( realIdx ) ) { return entry . getKey ( ) ; } } return realIdx ; }
Provides the render column index based on the real index
13,478
public void updateColumnMappings ( ) { columnMapping = new HashMap < > ( ) ; int realIdx = 0 ; int renderCol = 0 ; for ( final SheetColumn column : getColumns ( ) ) { if ( column . isRendered ( ) ) { columnMapping . put ( renderCol , realIdx ) ; renderCol ++ ; } realIdx ++ ; } }
Updates the column mappings based on the rendered attribute
13,479
public String getInvalidDataValue ( ) { final JavascriptVarBuilder vb = new JavascriptVarBuilder ( null , true ) ; for ( final SheetInvalidUpdate sheetInvalidUpdate : getInvalidUpdates ( ) ) { final Object rowKey = sheetInvalidUpdate . getInvalidRowKey ( ) ; final int col = getRenderIndexFromRealIdx ( sheetInvalidUpdate . getInvalidColIndex ( ) ) ; final String rowKeyProperty = this . getRowKeyValueAsString ( rowKey ) ; vb . appendProperty ( rowKeyProperty + "_c" + col , sheetInvalidUpdate . getInvalidMessage ( ) . replace ( "'" , "&apos;" ) , true ) ; } return vb . closeVar ( ) . toString ( ) ; }
Generates the bad data var value for this sheet .
13,480
public void renderRowUpdateScript ( final FacesContext context , final Set < String > dirtyRows ) { final String jsVar = resolveWidgetVar ( ) ; final StringBuilder eval = new StringBuilder ( ) ; for ( final String rowKey : dirtyRows ) { setRowVar ( context , rowKey ) ; final int rowIndex = rowNumbers . get ( rowKey ) ; final JavascriptVarBuilder jsRow = new JavascriptVarBuilder ( null , false ) ; final JavascriptVarBuilder jsStyle = new JavascriptVarBuilder ( null , true ) ; final JavascriptVarBuilder jsReadOnly = new JavascriptVarBuilder ( null , true ) ; int renderCol = 0 ; for ( int col = 0 ; col < getColumns ( ) . size ( ) ; col ++ ) { final SheetColumn column = getColumns ( ) . get ( col ) ; if ( ! column . isRendered ( ) ) { continue ; } final String value = getRenderValueForCell ( context , rowKey , col ) ; jsRow . appendArrayValue ( value , true ) ; final String styleClass = column . getStyleClass ( ) ; if ( styleClass != null ) { jsStyle . appendRowColProperty ( rowIndex , renderCol , styleClass , true ) ; } final boolean readOnly = column . isReadonlyCell ( ) ; if ( readOnly ) { jsReadOnly . appendRowColProperty ( rowIndex , renderCol , "true" , true ) ; } renderCol ++ ; } eval . append ( "PF('" ) . append ( jsVar ) . append ( "')" ) ; eval . append ( ".updateData('" ) ; eval . append ( rowIndex ) ; eval . append ( "'," ) ; eval . append ( jsRow . closeVar ( ) . toString ( ) ) ; eval . append ( "," ) ; eval . append ( jsStyle . closeVar ( ) . toString ( ) ) ; eval . append ( "," ) ; eval . append ( jsReadOnly . closeVar ( ) . toString ( ) ) ; eval . append ( ");" ) ; } eval . append ( "PF('" ) . append ( jsVar ) . append ( "')" ) . append ( ".redraw();" ) ; PrimeFaces . current ( ) . executeScript ( eval . toString ( ) ) ; }
Adds eval scripts to the ajax response to update the rows dirtied by the most recent successful update request .
13,481
public void renderBadUpdateScript ( final FacesContext context ) { final String widgetVar = resolveWidgetVar ( ) ; final String invalidValue = getInvalidDataValue ( ) ; StringBuilder sb = new StringBuilder ( "PF('" + widgetVar + "')" ) ; sb . append ( ".cfg.errors=" ) ; sb . append ( invalidValue ) ; sb . append ( ";" ) ; sb . append ( "PF('" + widgetVar + "')" ) ; sb . append ( ".ht.render();" ) ; PrimeFaces . current ( ) . executeScript ( sb . toString ( ) ) ; sb = new StringBuilder ( ) ; sb . append ( "PF('" ) . append ( widgetVar ) . append ( "')" ) ; sb . append ( ".sheetDiv.removeClass('ui-state-error')" ) ; if ( ! getInvalidUpdates ( ) . isEmpty ( ) ) { sb . append ( ".addClass('ui-state-error')" ) ; } PrimeFaces . current ( ) . executeScript ( sb . toString ( ) ) ; }
Adds eval scripts to update the bad data array in the sheet to render validation failures produced by the most recent ajax update attempt .
13,482
public void appendUpdateEvent ( final Object rowKey , final int colIndex , final Object rowData , final Object oldValue , final Object newValue ) { updates . add ( new SheetUpdate ( rowKey , colIndex , rowData , oldValue , newValue ) ) ; }
Appends an update event
13,483
public Integer getHeight ( ) { final Object result = getStateHelper ( ) . eval ( PropertyKeys . height ) ; if ( result == null ) { return null ; } return Integer . valueOf ( result . toString ( ) ) ; }
The height of the sheet . Note this is applied to the inner div which is why it is recommend you use this property instead of a style class .
13,484
public void setFilteredValue ( final java . util . List _filteredValue ) { getStateHelper ( ) . put ( PropertyKeys . filteredValue , _filteredValue ) ; }
Sets the filtered list .
13,485
public String getStyle ( ) { final Object result = getStateHelper ( ) . eval ( PropertyKeys . style , null ) ; if ( result == null ) { return null ; } return result . toString ( ) ; }
The style value
13,486
public String getSortOrder ( ) { final String result = ( String ) getStateHelper ( ) . eval ( PropertyKeys . sortOrder , SortOrder . ASCENDING . toString ( ) ) ; return result ; }
The sort direction
13,487
public void setSortOrder ( final java . lang . String sortOrder ) { final String orig = ( String ) getStateHelper ( ) . get ( PropertyKeys . origSortOrder ) ; if ( orig == null ) { getStateHelper ( ) . put ( PropertyKeys . origSortOrder , getStateHelper ( ) . eval ( PropertyKeys . sortOrder ) ) ; } getStateHelper ( ) . put ( PropertyKeys . sortOrder , sortOrder ) ; }
Update the sort direction
13,488
public String getErrorMessage ( ) { final Object result = getStateHelper ( ) . eval ( PropertyKeys . errorMessage ) ; if ( result == null ) { return null ; } return result . toString ( ) ; }
The error message to display when the sheet is in error .
13,489
private void encodeHandle ( final FacesContext context , final SlideOut slideOut ) throws IOException { final ResponseWriter writer = context . getResponseWriter ( ) ; String styleClass = SlideOut . HANDLE_CLASS ; if ( slideOut . getHandleStyleClass ( ) != null ) { styleClass = styleClass + " " + slideOut . getHandleStyleClass ( ) ; } writer . startElement ( "a" , null ) ; writer . writeAttribute ( "id" , getHandleId ( context , slideOut ) , null ) ; if ( slideOut . getHandleStyle ( ) != null ) { writer . writeAttribute ( "style" , slideOut . getHandleStyle ( ) , "style" ) ; } writer . writeAttribute ( "class" , styleClass , "styleClass" ) ; encodeIcon ( context , slideOut ) ; if ( slideOut . getTitle ( ) != null ) { writer . writeText ( slideOut . getTitle ( ) , "title" ) ; } writer . endElement ( "a" ) ; }
HTML markup for the tab handle .
13,490
private void encodeIcon ( final FacesContext context , final SlideOut slideOut ) throws IOException { if ( slideOut . getIcon ( ) == null ) { return ; } String icon = slideOut . getIcon ( ) . trim ( ) ; if ( icon . startsWith ( "ui" ) ) { icon = "ui-icon " + icon + " ui-slideouttab-icon" ; } final ResponseWriter writer = context . getResponseWriter ( ) ; writer . startElement ( "span" , null ) ; writer . writeAttribute ( "class" , icon , null ) ; writer . endElement ( "span" ) ; writer . write ( " " ) ; }
HTML markup for the tab handle icon if defined .
13,491
public DynaFormRow createRegularRow ( ) { final DynaFormRow dynaFormRow = new DynaFormRow ( regularRows . size ( ) + 1 , false , this ) ; regularRows . add ( dynaFormRow ) ; return dynaFormRow ; }
Creates a new regular row .
13,492
public DynaFormRow createExtendedRow ( ) { if ( extendedRows == null ) { extendedRows = new ArrayList < DynaFormRow > ( ) ; } final DynaFormRow dynaFormRow = new DynaFormRow ( extendedRows . size ( ) + 1 , true , this ) ; extendedRows . add ( dynaFormRow ) ; return dynaFormRow ; }
Creates a new extended row .
13,493
public void removeRegularRow ( final DynaFormRow rowToBeRemoved ) { final int idx = rowToBeRemoved != null ? regularRows . indexOf ( rowToBeRemoved ) : - 1 ; if ( idx >= 0 ) { removeRow ( regularRows , rowToBeRemoved , idx ) ; } }
Removes the passed regular row .
13,494
public void removeExtendedRow ( final DynaFormRow rowToBeRemoved ) { final int idx = rowToBeRemoved != null ? extendedRows . indexOf ( rowToBeRemoved ) : - 1 ; if ( idx >= 0 ) { removeRow ( extendedRows , rowToBeRemoved , idx ) ; } }
Removes the passed extended row .
13,495
public JavascriptVarBuilder appendRowColProperty ( final int row , final int col , final String propertyValue , final boolean quoted ) { return appendProperty ( "r" + row + "_c" + col , propertyValue , quoted ) ; }
appends a property with the name rYY_cXX where YY is the row and XX is he column .
13,496
public JavascriptVarBuilder appendText ( final String value , final boolean quoted ) { if ( quoted ) { sb . append ( "\"" ) ; if ( value != null ) { sb . append ( EscapeUtils . forJavaScript ( value ) ) ; } sb . append ( "\"" ) ; } else if ( value != null ) { sb . append ( value ) ; } return this ; }
Appends text to the var string
13,497
public JavascriptVarBuilder closeVar ( ) { if ( isObject ) { sb . append ( "}" ) ; } else { sb . append ( "]" ) ; } if ( isVar ) { sb . append ( ";" ) ; } return this ; }
Closes the array or object .
13,498
public String getHeaderText ( ) { final Object result = getStateHelper ( ) . eval ( PropertyKeys . headerText , null ) ; if ( result == null ) { return null ; } return result . toString ( ) ; }
The fixed column count .
13,499
public Boolean isReadonlyCell ( ) { return Boolean . valueOf ( getStateHelper ( ) . eval ( PropertyKeys . readonlyCell , Boolean . FALSE ) . toString ( ) ) ; }
Flag indicating whether this cell is read only . the var reference will be available .