Skip to main content
November 1, 2008
Question

Bizarre Error - Attribute Validation Error

  • November 1, 2008
  • 2 replies
  • 659 views
Hi there,

After searching on how to reverse an array, I eventually stumbled upon a nice little piece of Java which would apparently do the trick. However, when I call this function it doesn't return anything. When I put the variable within a CFDUMP tag, I suddenly get an error:

" Attribute validation error.
The tag requires the attribute var. "

But, the attribute IS there. See my example code below.

<cfscript>
function arrayRev(myArray) {
return createObject("java", "java.util.Collections").reverse(myArray);
}
</cfscript>

<!--- This line DOES return my array, so now I know it is present --->
<cfdump var="#application.objRecursion.getBreadcrumbArray(url.item_id)#" />

<!--- This line gives me the error about the attribute VAR not being present. Clearly it is --->
<cfdump var="#arrayRev(application.objRecursion.getBreadcrumbArray(url.item_id))#" />

Now, clearly this is something to do with the function.

So, I have two questions:

1. Why is this function not working?
2. What is wrong with this function that is causing the error?

Many thanks,
Mikey.
    This topic has been closed for replies.

    2 replies

    Inspiring
    November 1, 2008
    quote:

    Originally posted by: Kapitaine
    Hi there,

    After searching on how to reverse an array, I eventually stumbled upon a nice little piece of Java which would apparently do the trick. However, when I call this function it doesn't return anything. When I put the variable within a CFDUMP tag, I suddenly get an error:

    " Attribute validation error.
    The tag requires the attribute var. "

    But, the attribute IS there. See my example code below.

    <cfscript>
    function arrayRev(myArray) {
    return createObject("java", "java.util.Collections").reverse(myArray);
    }
    </cfscript>

    <!--- This line DOES return my array, so now I know it is present --->
    <cfdump var="#application.objRecursion.getBreadcrumbArray(url.item_id)#" />

    <!--- This line gives me the error about the attribute VAR not being present. Clearly it is --->
    <cfdump var="#arrayRev(application.objRecursion.getBreadcrumbArray(url.item_id))#" />

    Now, clearly this is something to do with the function.

    So, I have two questions:

    1. Why is this function not working?
    2. What is wrong with this function that is causing the error?

    Many thanks,
    Mikey.



    Inspiring
    November 1, 2008
    If you are going to use java, get to know the API's. It will save you a lot of future headaches.

    > This line gives me the error about the attribute VAR not being present. Clearly it is
    > return createObject("java", "java.util.Collections").reverse(myArray);

    No it is not. Look at the API. java.util.Collections.reverse(..) returns void (ie nothing). So your function returns nothing.
    http://java.sun.com/j2se/1.5.0/docs/api/java/util/Collections.html#reverse(java.util.List)
    November 1, 2008
    quote:

    Originally posted by: -==cfSearching==-
    If you are going to use java, get to know the API's. It will save you a lot of future headaches.

    > This line gives me the error about the attribute VAR not being present. Clearly it is
    > return createObject("java", "java.util.Collections").reverse(myArray);

    No it is not. Look at the API. java.util.Collections.reverse(..) returns void (ie nothing). So your function returns nothing.
    http://java.sun.com/j2se/1.5.0/docs/api/java/util/Collections.html#reverse(java.util.List)


    Yes, I really should start looking at the docs, but I just happened to come accross this, I didn't make a point of using it because I know much about Java, I'm still very much learning CF! ha!!

    Hmm, well, on a side note then, all I really want to do is reverse an array. Does anyone have an idea of how to do this. The only solution other than this that I have seen is to convert this to a list, use a CF reverse and then convert is back to an array. However, this solution is a bit dirty and doesn't always return the correct results e.g. reversing the characters in a whole word etc.

    Thanks for your help and advice.

    Any further help or advice would be greatly appreciated.

    Many thanks!
    Mikey.
    Inspiring
    November 1, 2008
    > createObject("java", "java.util.Collections").reverse(myArray);
    > Hmm, well, on a side note then, all I really want to do is reverse an array

    It does work. Just not the way you are thinking ;-) It operates in place. In other words, it modifies the array you pass in, rather than creating and returning a new one. Similar to the CF arrayAppend(..) function.

    To see the results just dump the #myArray# object.