Hi all,

I'm using Reactor with Model-Glue, and I'm using makeEventBean() in my
controller to grab all of the values from a submitted form and place them
into my reactor record object.  This works very well, except for the often
frustrating html checkbox issue.  That is, when you submit a form with a
checkbox, and the checkbox isn't checked, nothing is submitted with your
form.  Therefore, makeEventBean() cannot set my record object correctly when
a user un-checks a field as that information is not passed to it.

A workaround to this problem is to also include a hidden form field with the
same name, with a blank value.  That will insure that I always receive a
value submitted with my form.  If the user checks the box I'll get a 1
(which is the value assigned to the checkbox) and if they don't check it, or
un-check it, I'll get a blank value. This solves the first problem, but
introduces a new problem:

I'm using MS SQL Server bit fields to store all of my boolean values (which
are edited by a user via checkboxes).  The problem is that blank is not a
valid value for a bit field in SQL Server.  In my previous, home-grown ORM,
I dealt with this by simply wrapping any values that are being passed to bit
fields with the ColdFusion Val() function.  Hence, 1 remains 1, but blank
becomes 0.  I would like to be able to do this with Reactor as well.

One of my goals here is to have the ORM do this form me, so I don't have to
write a specific line of code for every checkbox that appears on every form
in my app (which is what I'm doing currently).  I dug into the core and
discovered that I can do this quite simply by adding a line (in 4 places) to
the dao.project.xsl file.  If I take the code block that looks like this:

value="<xsl:choose>
        <xsl:when test="@dbDataType =
'uniqueidentifier'">#Left(arguments.to.<xsl:value-of select="@alias" />,
23)#-#Right(arguments.to.<xsl:value-of select="@alias" />, 12)#</xsl:when>
        <xsl:otherwise>#arguments.to.<xsl:value-of select="@alias"
/>#</xsl:otherwise>
</xsl:choose>"

And replace it with this:

value="<xsl:choose>
        <xsl:when test="@dbDataType =
'uniqueidentifier'">#Left(arguments.to.<xsl:value-of select="@alias" />,
23)#-#Right(arguments.to.<xsl:value-of select="@alias" />, 12)#</xsl:when>
        <xsl:when test="@dbDataType = 'bit'">#Val(arguments.to.<xsl:value-of
select="@alias" />)#</xsl:when>
        <xsl:otherwise>#arguments.to.<xsl:value-of select="@alias"
/>#</xsl:otherwise>
</xsl:choose>"

Then my issue is dealt with.  I realize that I'm sacrificing a layer of
datatype validation here, as any non-numeric value assigned to this field
will simply be converted to 0.  I'm fine with that, but I know that you'll
probably not want to alter the behaviour of the actual core in this way.

So, my question is, has anyone come up with a different way of addressing
this issue?  Is there a place for me to put this code in my own customized
reactor objects (but only in one place, not for every single checkbox)? Do
you have any other comments on how I've dealt with it (positive or
negative)?

Thanks,
Bob





-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Reactor for ColdFusion Mailing List
[email protected]
Archives at: http://www.mail-archive.com/reactor%40doughughes.net/
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Reply via email to