I am having difficulty with the behavior of a "bean".  In this case a
document bean.
In my listener method I have
<cfset document = createObject("component", "model.document").init( ID
= arguments.event.getArg("id") ) />

This instantiates the document bean for the id passed in.
But for a new document there is no id. So I want to modify the above
instantiation to:
<cfset document = createObject("component", "model.document").init() /
>

What I expected was for this to create an "empty" document bean with
an id=0. Here's the relevant bean definition code:

<cfcomponent name="document" hint="This is a document Bean">
        <cfset variables.id = 0 />
        <cfset variables.name = "" />
        <cfset variables.description = "" />
...
        <cffunction name="init" displayname="init" hint="Bean for documents"
access="public" output="false" returntype="document">
                <cfargument name="ID" type="numeric" required="false" 
default="0"
hint="ID" />
                <cfargument name="Name" type="string" required="false" 
default=""
hint="NAME" />
                <cfargument name="Description" type="string" required="false"
default="" hint="DESCRIPTION" />
...
                <cfset setID(Arguments.ID) />
                <cfset setName(Arguments.Name) />
                <cfset setDescription(Arguments.Description) />
...
                <cfreturn this />
        </cffunction>

        <cffunction name="getId" access="public" hint="Getter for id"
output="false" returntype="numeric">
                <cfreturn variables.id />
        </cffunction>

        <cffunction name="setId" access="private" hint="Setter for id"
output="false" returntype="void">
                <cfargument name="id" hint="ID" required="yes" type="numeric" />
                <cfset variables.id = arguments.id />
        </cffunction>

        (... more getters and setters here...)

</cfcomponent>

The ID is of type "numeric" but is not required and defaults to 0. But
I get a framework error:

Mach-II Exception
Message: The ID argument passed to the init function is not of type
numeric.
Detail: If the component name is specified as a type of this argument,
its possible that a definition file for the component cannot be found
or is not accessible.
Extended Info:
Tag Context:
 .../model/document.cfc (36)
 .../listeners/documentListener.cfc (59)

If I explicitely pass in a 0 for ID I believe it will accept it.  But
I was expecting the bean to accommodate the null parameter list and
default to the default ID=0 which is numeric. I'm also not sure what
the Details in the error means. Why won't the bean construct a default
bean with no parameters passed in?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to Mach-II for CFML list.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/mach-ii-for-coldfusion?hl=en
SVN: http://greatbiztoolsllc.svn.cvsdude.com/mach-ii/
Wiki / Documentation / Tickets: 
http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/
-~----------~----~----~----~------~----~------~--~---

Reply via email to