Flex Builder Redux: How does this MXML tag work again?

FlexBuilderPackages

I posted last year about how to get help on an MXML tag in Flex Builder, but I have another tip that I've been using quite a lot lately.

The source to the Flex framework is actually included with the Flex SDK built into Flex Builder. If you want to view the actual source code to an MXML tag (like RemoteObject) or even an ActionScript class or method, you can hold down Command (on the Mac) or Control (Windows) and hover over the name of the object in Source view. The class should be underlined, and is now a link to the source code of that class.

But it doesn't stop with the Flex framework: this even works with your own classes. Why is this important? If you have your project source files structured into nice named packages (like com.mycompany.myproject.*), you can get some pretty deep folder structures (see screen shot at right). Eclipse will generally collapse these folders for you if you're using the Java developer tools, but no such luck with Flex Builder.

By using the Command/Control-Click trick, you can pop anywhere within your source code base fairly quickly. This is really handy when you're chasing down a bug.

Building an RIA through Collaborative Design and Prototyping : Preamble

We're in the midst of building an interesting Rich Internet Application for educational assessment using Flex. We've had a lot of success with our process thus far, so I thought it would be helpful to document it as a means of discussing it and maybe improving it for our next project.

One of the great aspects of this particular project is that we've done the design collaboratively with an interdisciplinary team, including technologists, instructional designers, and even a faculty member or two.

Here's a pic of our screen designs and the application state diagram:

Rubricator Application States

I'll break this down into detail in upcoming posts.

Next up: Iterative design.

CFQUERY and autonumber primary keys

After reading a post by Ben Nadel, it occurred to me that I should write up my technique of getting new autogenerated primary key values back from the database.

It's very common for database designers to use columns that generate a unique, artificial primary key value for every row inserted into a database table. Different platforms have different names for this type of column:

  • Microsoft SQL Server: identity column property
  • Microsoft Access: AutoNumber field type
  • MySQL: AUTO_INCREMENT column property

PostgreSQL and Oracle use an alternative method called a sequence. Sequences are easier to use in some ways, and the technique I'll describe below doesn't really apply.

If you have child tables in your database related to your main table with Foreign Key constraints, you're going to need to retrieve this autogenerated value before you can insert data into these child tables.

Let's take a typical INSERT statement that pulls data from an HTML form POST operation:


<cfquery name="insertNewRecord" datasource="myDB">
INSERT INTO tblPeople (
nameLast,
nameFirst,
emailAddress
) VALUES (
<cfqueryparam value="#form.nameLast#" cfsqltype="cf_sql_varchar" />
<cfqueryparam value="#form.nameFirst#" cfsqltype="cf_sql_varchar" />
<cfqueryparam value="#form.emailAddress#" cfsqltype="cf_sql_varchar" />
)
</cfquery>

Although INSERT CFQUERY tags don't require a name attribute, I make sure to add one here. You'll see why in a moment.

One handy property of the CFQUERY tag is that it can contain multiple SQL queries if you separate them with semicolons. You can use this trick to fetch the newly-created ID in this first query. This example works with MS SQL Server 2000 or higher:


<cfquery name="insertNewRecord" datasource="myDB">
INSERT INTO tblPeople (
nameLast,
nameFirst,
emailAddress
) VALUES (
<cfqueryparam value="#form.nameLast#" cfsqltype="cf_sql_varchar" />
<cfqueryparam value="#form.nameFirst#" cfsqltype="cf_sql_varchar" />
<cfqueryparam value="#form.emailAddress#" cfsqltype="cf_sql_varchar" />
);

SELECT SCOPE_IDENTITY() AS peopleID;
</cfquery>

Because I named the CFQUERY instance, I can now reference the autogenerated ID value in my succeeding queries as:


#insertNewRecord.peopleID#

Don't forget to wrap your entire batch of related CFQUERY tags inside a CFTRANSACTION tag to make them one complete operation.

One final note: The SCOPE_IDENTITY() function used above only works with SQL Server 2000 and higher. Anyone on SQL Server 7 (??) and before must use the special @@IDENTITY variable to accomplish the same thing. @@IDENTITY has some limitations with regards to databases with triggers, and may not retrieve the right value in all cases. Here's a more thorough explanation of the problem.

People using MySQL can substitute the function LAST_INSERT_ID() to accomplish the same thing.

As Seen On Twitter....

"get to go play with Sharepoint for a bit. Have to launch Parallels so I can get into the site. That counts as strikes 1 through 94. - dnorman

FlexBuilder 3 for academia

Since FlexBuilder 3 was released last week, I decided to hunt around for the 'free to academics' offer and see if it applies to FlexBuilder 3. Here's where it lives now:

http://www.flexregistration.com/

Interesting things to note:

  1. It apparently does apply to staff too (woo!)
  2. You can request more than one license if you're using it for a class or a lab. That will be a real time-saver.
  3. You have to scan your ID and submit it with the form. Uhh... scan? paper? I don't have a scanner hooked up anywhere, so I took a photo of my ID with the iSight on MacBook Pro and tried that, thumb included free of charge.

The action page tells you to allow a few weeks for processing the request, but mine was approved the next day.... that's service!

Heading to CodeMash '08

I'm really looking forward to CodeMash. The slate of speakers and topics looks fantastic; It's really nice to look at a conference schedule and see a lot of topics that are totally new to me.

One thing I'm curious about is Scala. I've been working with a research group lately on a project using Intelligent Agents, and through that was introduced to the idea of Functional Programming. Somehow I missed seeing this in my undergraduate days, though I remember my peers complaining about Scheme in one of the senior-level computer science courses.

Some of the talks on Groovy and Grails seem interesting, too. The Ruby on Rails movement has certainly sparked some innovation in the Web Development community, and I like seeing those ideas cross-ported into the technologies I have more of an affinity for, such as Java and ColdFusion. Having recently built a somewhat painful full-scale Java application, there may be something useful here.

Eolas Nightmare Coming to an End?

After two years of patent-induced pain, Microsoft will be removing the Eolas "fix" from IE in April of next year.

At that point, users should no longer be forced to click on embedded active content (such as Flash, Java, Quicktime, or Windows Media) to interact with it after April '08. Consequently, we will not be required forced to write out our object tags with JavaScript.

I can only hope this will come to pass! This one change was a major setback to Web Standards and Web Accessibility efforts.

ColdFusion Beta program for Leopard and 64-bit OSs

Ready to move your Macs to Leopard, but waiting for CF support? There's a beta opening now. See Kristen Shofield's Blog for more information.

Unit Testing and Subversion - Where should I put the test classes?

I'm starting a strong push to institute Unit Testing in a relatively new project; I figure it will be easier to really get into the habits in a new project from the start, rather than trying to steer some of our ancient existing projects in that direction right away. But I've hit a snag... where should I keep the test classes?

We've been using Subversion to manage our project files since shortly after I started here... getting us into source control was one of my first imperatives. So our code is laid out nicely in folders:


Project A
|____ src
|____ lib
|____ docs
|____ db

Project B
|____ src
|____ lib
|____ docs
|____ db

In the src folder, I have things organized in packages like


src/edu.psu.ist.project-a.component-a
src/edu.psu.ist.project-a.component-b

So where do I put the test cases? I could put them in a test package at the root of the project:


src/edu.psu.ist.project-a.test.component-a
src/edu.psu.ist.project-a.test.component-b

But what I'm really leaning toward is mirroring the main folder structure of the package in a test package in the root of the repository, at the same level as the src folder:


src/edu.psu.ist.project-a.component-a
src/edu.psu.ist.project-a.component-b
test/testComponent-a
test/testComponent-b

My thinking is that the classes in the test package would not get deployed with my actual project code, so they shouldn't be in the real source package tree. But I'm still not sure.

Flex Builder: How does this MXML tag work again?

I'm doing a lot more Flex development lately, and I found a nice little keyboard shortcut in Flex Builder 3 that I wanted to note someplace.

If you want the documentation on an MXML tag, select the tag name and hit Shift-F2.

More Entries

BlogCFC was created by Raymond Camden. This blog is running version 5.9.1. Contact Blog Owner