Rip's Domain

Transfer woes

Posted in ColdFusion, Rants by rip747 on May 8, 2007

So I’m finally trying to take the time and learn Transfer and already I’m running into problems that I thought that someone else would have and answer for.

Here is my problem: I want to be able to set the null value for all my types to be an empty sting. The reason for this is because when someone submits something from a web form, everything gets passed back to the server as a string, since there are no types on the web. So someone could leave a quantity field or a time field blank and I want to be able to set something like this to null in my database.

The thing is that if I tell Transfer to use a blank string as the nullValue for a numeric type, it spits it’s skull out. Here is the nullValue portion of my transfer.xml:

<nullValues>
<numeric value=””/>
<date value=””/>
<boolean value=””/>
<UUID value=””/>
<GUID value=””/>
</nullValues>

So my question is, how are other people handling this? While searching the web I found this post in Google Groups about the exact same problem where Sean Corfield suggested to just use decorators. I don’t like that approach since it basically just adds more code and if I have to write a get / set method for every column in my database, then I might as well not even use Transfer.

2 Responses

Subscribe to comments with RSS.

  1. Sean Corfield said, on May 16, 2007 at 12:25 am

    You can’t circumvent the type checking without decorators so you cannot arbitrarily pass “” into Transfer object methods that expect numeric or date or whatever.

    Remember that Transfer objects are full business objects, not just untyped beans. If you want something to just stuff form values into, you need to have simple beans that accept strings (and probably have a validate() method). Then, when the data has been correctly processed, use Transfer to persist it (by copying the valid data into a Transfer object).

    You might also want to look at the get{FieldName}IsNull() and set{FieldName}Null() methods that Transfer generates if you specify a property is nullable=”true”.

  2. rip747 said, on May 16, 2007 at 4:24 pm

    So I guess I’m not using transfer thenđŸ˜‰


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: