Viewing Entries For
August
2009
[clear date selection]
I use a lot of beans in my CFML applications. When I use the term beans, I'm referring to a particular naming convention on components (CFCs), much like the JavaBean concept. My beans have getters/setters that all return/receive string values. This makes it possible for the MVC controller to populate a bean the user input, without any exceptions thrown due to incorrect data type or format. Validation of the bean properties happens later, and the results of the validation are stored inside the bean. When the bean is then handed off to a MVC view, the validation messages can be displayed alongside the field label. Consider the following model:
In most situations, the system instantiates a beans.Bean and calls the appropriate getter and setter methods. However, this particular component doesn't actually have any getters or setters -- it has an onMissingMethod() handler that mimics their behavior. This generic bean can stand in place of any real bean. It creates its own validation.ValidationMessages instance and uses a datatype.Collection to keep track of its properties. Because it always knows what properties it contains, other components can easily move values in and out of the bean. A beans.BeanUtils component exists to simplify the common task of loading and unloading beans:
None of the information I've covered so far is particularly new or innovative. However, I recently encountered a special situation using the beans.Bean that prompted me to do some experimenting. While working on a search interface (think: Google advanced search options), I wanted to put all the search information into a bean to pass off to the search service. However, I also wanted a method (unrelated to getters and setters) that returns a properly URL-encoded string for use in the view. It seemed trivial to extend the bean and add the getSearchArgs() method. Doing so, unfortunately, breaks the onMissingMethod() mechanism for supporting arbitrary getters and setters. The solution is to implement the getters and setters using the extended component's managed structure.
<cfcomponent extends="beans.Bean">
<cffunction name="init" returntype="SearchBean">
<cfset super.init("query,...") />
<cfreturn this />
</cffunction>
<cffunction name="getSearchArgs" returntype="string">
<!-- Return URL-encoded arguments -->
...
</cffunction>
<cffunction name="getQuery" returntype="string">
<cfreturn getProperty("query") />
</cffunction>
<cffunction name="setQuery" returntype="void">
<cfargument name="query" type="string" required="true" />
<cfset setProperty("query", arguments.query) />
</cffunction>
...
</cfcomponent>
The getProperty() and setProperty() methods come from the extended component (super class), and the init method (constructor) sets up the appropriate property names. The onMissingMethod() mechanism for supporting dynamic property getter/setters is not used, or needed. Simple, right?
CFML
|
Posted
8/22/09
@ 9:00 PM
by Joseph Lamoree
I recently purchased a Vantec NexStar eSATA/USB dock for 3.5" and 2.5" drives. It's connected to Mac Pro with a PCI Express SATA II adapter with two eSATA ports and a 6' eSATA cable. The drive dock comes with USB and eSATA cables, but they're only 3' long — that's not long enough. I used the USB connector on the dock before the eSATA card was installed. It works as expected, but the performance of the external SATA is worth the effort to install the card.
The Mac Pro Quad-Core Intel Xeon 2.8 GHz (early 2008) has 4 PCI slots (two 16x and two 4x). The eSATA card must be installed in one of the 4x slots. I understand that the Mac Pro has two available SATA ports, but I didn't research the connector kits to expose those to external drives. The card I received was manufactured by Best Connectivity and uses a Silicon Image SiI3132 controller chip. A driver CD is included, however my SOP is to download the current version. In this case, the drivers are provided directly by the Silicon Image support page. Before purchasing the card, I did a bit of Googling to make sure it worked with Mac OS X 10.5. The results weren't totally convincing, but I decided to give it a try. The driver installs a kernel driver clearly marked:
nikki:Desktop joseph$ kextstat | grep -i sil
53 0 0x86782000 0x14000 0x13000 com.SiliconImage.driver.Si3132 (1.1.9) <52 17 12>
The adapter card and dock are working well now. The transfer speed is very good, and it's really convenient to swap drives so easily. Of course, the drive gets warm without active cooling, but it's only meant for temporary use. I need a solution for indexing drives to make locating files contained on offline drives easier.
I saw a tip from @linuxalive about obtaining the apparent public IP address from the current machine. In a blog post last month, Racker Hacker wrote about his frustration viewing the HTML returned by the service DynDNS offers at checkip.dyndns.org. He created a site at icanhazip.com that echos only the IP in the server response. (A commenter on that post mentioned whatismyip.org for the same result.)
With these HTTP services, it's possible to include the result in shell scripts or programs that do something useful. Here are two examples using Wget and cURL:
wget -O - -q icanhazip.com
curl whatismyip.org
Using a system without HTTP aware apps, it's possible to get the same result with nc or Netcat
H=icanhazip.com
echo -e 'GET / HTTP/1.0\nHost: '$H'\n' | nc $H 80
Of course, you'll see the HTTP response headers using the last method. To show only the IP address, pipe it through grep:
grep -o -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$'
Surely that was more than you wanted to know. ;)
It hadn't occurred to me previously, but today I wanted to dynamically the change the favicon file used on a site/page. It's been possible using JavaScript in Firefox and Opera for at least three years, and there is a really clean library by Michael Mahemoff that makes the task trivial. This method doesn't work in Microsoft Internet Explorer or Safari. There might be another mechanism to dynamically add and remove link elements to the document head, but I haven't seen it yet.
While searching for information, I happened upon DEFENDER of the favicon -- a classic arcade game played through a 16x16 pixel portal. Crazy.
JavaScript
|
Posted
8/11/09
@ 2:50 AM
by Joseph Lamoree