Kind of going along with what I showed in the other thread (and some
folks here may start noting that this is partially about CFCs and
partially about Fusebox, but since the focus is on how the CFCs work I
think they will forgive us). You are getting into territory beyond
what the sample app is meant to show. My approach on this is
constantly evolving, but you would want to call a validate() method on
the Product before you run the addProduct() method, probably in the
XML but possibly in the ProductManager as well.

This whipped-up sample keeps changing, but something like this:

<fuseaction name="register" access="public">
        <xfa name="processRegistration" value="processregistration" />
        <invoke object="application.TOManager" 
                        methodcall="getTO( TOType='User', checkScope=variables 
)" 
                        returnvariable="userTO"/>
        <do action="v_user.registerForm" contentvariable="content.pageContent"/>
</fuseaction>

<fuseaction name="processregistration" access="public">
        <invoke object="application.TOManager" 
                        methodcall="getTO( TOType='User', values=attributes )" 
                        returnvariable="userTO"/>
        <invoke object="application.userManager" 
                        methodcall="getUser( userTO )" 
                        returnvariable="user"/>
        <if condition="#user.validate()#">
                <true>
                        <!-- Was the registration successful? -->
                        <invoke object="application.userManager" 
                                        methodcall="processRegistration( user 
)"/>
                        <relocate url="#formatURL( 
'#myFusebox.originalCircuit#.success' )#"/>
                </true>
                <false>
                        <!-- If registration was not successful, display the 
registration
form again. -->
                        <invoke object="user" 
                                methodcall="getValidationErrors()" 
                                returnvariable="validationErrors" />            
                                
                        <do action="v_components.formatValidationErrors"
contentvariable="content.validationErrors" />
                        <do action="register" />
                </false>
        </if>
</fuseaction> 

On 9/1/05, wolf2k5 <[EMAIL PROTECTED]> wrote:
> On 8/30/05, Brian Kotek <[EMAIL PROTECTED]> wrote:
> > It would create an instance of a new Product object, populate it with
> > initial values (using the passed attributes struct), and return the
> > populated Product object:
> >
> > <cffunction name="getProduct" access="public" returntype="Product"
> > output="false" roles="" hint="Return a new Product instance.">
> >         <cfargument name="initialValues" type="struct" required="true"
> > hint="Initial values for the new Product." />
> >         <cfreturn createObject( 'component', 'Product' ).init(
> > argumentCollection=arguments.initialValues ) />
> > </cffunction>
> 
> Brian,
> 
> I am looking better into your Wegot Wedgets OO application code and I
> have a few questions about the form for adding a new product.
> 
> Here is a snippet from the XML file for the admin circuit:
> 
> 
> <fuseaction name="addProduct">
>         <set value="#application.productManager.addProduct( attributes )#" />
>         <relocate url="index.cfm?fuseaction=browse.showCatalog" type="server" 
> />
> </fuseaction>
> 
> 
> Here is the code for the "addProduct" method of the "ProductManager"
> component (I removed out the image upload code to make things easier):
> 
> 
> <cffunction name="addProduct" hint="Add a Product to the Catalog."
> access="public" returntype="void" output="false">
>         <cfargument name="productData" type="struct" required="true" />
>         <cfset var local = structNew() />
>         <cfset local.product = createObject( 'component',
> 'wegotwidgetsoo.com.Product' ).init() />
>         <cfset local.product.setProductByStruct( arguments.productData ) />
>         <cfset variables.instance.productDAO.create( local.product ) />
> </cffunction>
> 
> 
> Here is the code for the "setProductByStruct" method of the "Product" 
> component:
> 
> 
> <cffunction name="setProductByStruct" hint="I set the instance data
> for the Product." access="package" returntype="void" output="false">
>         <cfargument name="strGetProduct" type="struct" required="true" />
>         <cfscript>
>         if ( structKeyExists( arguments, 'productID' ) ) {
>                 variables.instance.productID = 
> arguments.strGetProduct.productID;
>         }
>         else {
>                 variables.instance.productID = '';
>         }
>         variables.instance.productName = arguments.strGetProduct.productName;
>         variables.instance.productDescription =
> arguments.strGetProduct.productDescription;
>         variables.instance.price = arguments.strGetProduct.price;
>         </cfscript>
> </cffunction>
> 
> Now to the questions ...
> 
> I noticed that I am able to add a product with all empty fields (name,
> description and price).
> I'd like to avoid that, what would be the best way to do it
> server-side (I'll add JS validation client-side too)?
> Add the "validate" method to the "Product" component (as you suggested
> in the previous emails) and put a check for empty fields in it?
> 
> Also, I noticed that if I rename one of the form fields (e.g.
> productName to anotherName), when I submit the form, I get an error in
> the "Product" component, e.g.:
> 
> 
> "Element STRGETPRODUCT.PRODUCTNAME is undefined in ARGUMENTS."
> 
> 
> I'd like to avoid that error and put a check to see if all the
> required fields exist in the Arguments structure, before trying to
> evaluate them.
> How would you handle that in a Fusebox MVC OO application like that one?
> I am not sure how to change your application to handle that ...
> 
> Also, what is the advantage of using an "init" method with no
> parameters and instantiating an object with empty variables and then
> using the "setProductByStruct" method to set the variables to the
> actual values for the object instance? Isn't it simpler just using an
> "init" method that takes the same parameters now required by the
> "setProductByStruct" method?
> 
> I'm am sorry for all the questions, I am a bit confused about all this
> OO stuff, since it's very new for me.
> 
> Thanks again for all your help and sample applications.
> 
> 
> ----------------------------------------------------------
> You are subscribed to cfcdev. To unsubscribe, send an email to 
> [email protected] with the words 'unsubscribe cfcdev' as the subject of the 
> email.
> 
> CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
> (www.cfxhosting.com).
> 
> CFCDev is supported by New Atlanta, makers of BlueDragon
> http://www.newatlanta.com/products/bluedragon/index.cfm
> 
> An archive of the CFCDev list is available at 
> www.mail-archive.com/[email protected]
> 
> 
>


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]


Reply via email to