Professional Web Applications Themes

Array Reference - Coldfusion - Advanced Techniques

This loop does not seem to like the reference to the array via application.production.getWorkLoad() where i is the index. Is there a way to reference this array without dumping it into a local variable on the page? Thanks for the help! Andy Powell <cfloop from="1" to="#ArrayLen(application.production.getWorkLoad() )#" index="i"> <tr> <td><cfoutput>#application.production.getWorkLoad( )[i].id#</cfoutput></td> <td><cfoutput>#application.production.getWorkLoad( )[i].client.name#</cfoutput> </td> <td><cfoutput>#application.production.getWorkLoad( )[i].agent#</cfoutput></td> </tr> </cfloop>...

  1. #1

    Default Array Reference

    This loop does not seem to like the reference to the array via
    application.production.getWorkLoad() where i is the index. Is there a way to
    reference this array without dumping it into a local variable on the page?

    Thanks for the help!

    Andy Powell

    <cfloop from="1" to="#ArrayLen(application.production.getWorkLoad() )#"
    index="i">
    <tr>
    <td><cfoutput>#application.production.getWorkLoad( )[i].id#</cfoutput></td>

    <td><cfoutput>#application.production.getWorkLoad( )[i].client.name#</cfoutput>
    </td>
    <td><cfoutput>#application.production.getWorkLoad( )[i].agent#</cfoutput></td>
    </tr>
    </cfloop>

    ajpowellatl Guest

  2. #2

    Default Re: Array Reference

    > application.production.getWorkLoad() where i is the index. Is there a way to
    > reference this array without dumping it into a local variable on the page?
    Not the way you're trying to do it, no.

    However you could note that a CF array is in fact an implementation of a
    Java vector, so you can do this:

    i = application.production.getWorkLoad().iterator();
    while (i.hasNext()){
    writeOutput(i.next() & "<br />");
    }

    There's a CHANCE that Macromedia (or Adobe, by the time it becomes an
    issue) might decide to stop making an Array be an implementation of a
    Vector, in which case this code might stop working. Not sure the odds of
    that happening are worth worrying about though.

    --

    Adam
    Adam Cameron Guest

  3. #3

    Default Re: Array Reference

    This works great, with one exception. When it gets to the last column of the
    last row, it bombs out. This is the error it throws:

    java.util.NoSuchElementException

    Any ideas? The data is there in the object (it's an array of objects)

    ajpowellatl Guest

  4. #4

    Default Re: Array Reference

    > This works great, with one exception. When it gets to the last column of the
    > last row, it bombs out. This is the error it throws:
    >
    > java.util.NoSuchElementException
    >
    > Any ideas? The data is there in the object (it's an array of objects)
    Can you post your code?

    --

    Adam
    Adam Cameron Guest

  5. #5

    Default Re: Array Reference

    Here you go:

    <cfscript>
    i = application.production.getWorkLoad().iterator();
    while (i.hasNext())
    {
    writeOutput("<tr>");
    writeOutput("<td>");
    writeOutput(i.next().id);
    writeOutput("</td>");
    writeOutput("<td>");
    writeOutput(i.next().client.name);
    writeOutput("</td>");
    writeOutput("<td>");
    writeOutput(i.next().agent);
    writeOutput("</td>");
    writeOutput("</tr>");
    }
    </cfscript>

    ajpowellatl Guest

  6. #6

    Default Re: Array Reference

    You don't want to make multiple calls to i.next(). Every call to i.next() takes
    you to the next item in the iterator.

    Try:

    <cfscript>
    i = application.production.getWorkLoad().iterator();
    while (i.hasNext())
    {
    tmp = i.next();
    writeOutput("<tr>");
    writeOutput("<td>");
    writeOutput(tmp.id);
    writeOutput("</td>");
    writeOutput("<td>");
    writeOutput(tmp.client.name);
    writeOutput("</td>");
    writeOutput("<td>");
    writeOutput(tmp.agent);
    writeOutput("</td>");
    writeOutput("</tr>");
    }
    </cfscript>

    Kronin555 Guest

Similar Threads

  1. Can't reference array that exists....i checked!
    By melikey webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 1
    Last Post: January 28th, 05:02 AM
  2. list ($d, $row) = each ($array) by reference?
    By Jochen Daum in forum PHP Development
    Replies: 3
    Last Post: December 9th, 01:14 AM
  3. Replies: 0
    Last Post: October 30th, 12:46 AM
  4. Array Reference Practice Help
    By perl@swanmail.com in forum PERL Beginners
    Replies: 3
    Last Post: October 26th, 04:38 PM
  5. Array slicing through a reference: Inefficient?
    By Ethan Brown in forum PERL Miscellaneous
    Replies: 2
    Last Post: September 17th, 07:44 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139