ColdFusion framework 1- form action to to insert database

479 views
Skip to first unread message

Ram

unread,
Aug 21, 2014, 4:45:55 PM8/21/14
to framew...@googlegroups.com
I am learning the framework1 and tried to do simple coldfusion program to insert data in to database after submitting a form.

my simple form  person.cfm is in views/main


    <form name = "savePerson" action="#buildurl('person')#" method="post">


In the form action I put controller "person.cfc" 

I have person.cfc in controllers folder with code in the component

    <cffunction name="person">
    
    <cfif isDefined("rc.savePerson")>
    
    <cfset variables.services.person.savePerson()>
    
    </cfif>
    
    </cffunction

and sql insert statement in person.cfc with function name = savePerson in the services folder.

Application.cfc has code

     function setupApplication() {
    
    var bf = new framework.ioc( "services" );
    
    setBeanFactory( bf );
    
     }

When I submit the form I get the error below

    Original exception in onRequest
    
    The action person.person failed.
    
    Element SERVICES.PERSON is undefined in a Java object of type class [Ljava.lang.String; referenced as ''
    
    (Expression)

but there is a person.cfc in  controllers, services. I don't know if I need a beans folder.
My question is what should I write for form action and how framework1 call the file in services folder to run insert statement via controller.

Thanks in advance!! 
Ram

Matt Quackenbush

unread,
Aug 21, 2014, 5:01:12 PM8/21/14
to framew...@googlegroups.com
Hello. Have you had a chance to check out the documentation and the sample applications? I think those will go a long way toward helping you understand how the framework is designed.

https://github.com/framework-one/fw1/wiki




--
--
FW/1 on RIAForge: http://fw1.riaforge.org/
 
FW/1 on github: http://github.com/framework-one/fw1
 
FW/1 on Google Groups: http://groups.google.com/group/framework-one
---
You received this message because you are subscribed to the Google Groups "framework-one" group.
To unsubscribe from this group and stop receiving emails from it, send an email to framework-on...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Blake

unread,
Aug 21, 2014, 7:24:59 PM8/21/14
to framework-one

Do you have a persons.cfc under services folder?

Ram

unread,
Aug 21, 2014, 9:35:13 PM8/21/14
to framew...@googlegroups.com
Yes. I have the person.cfc in the services folder. My question is how  can I call the service and the method in person.cfc?

Sean Corfield

unread,
Aug 21, 2014, 10:13:02 PM8/21/14
to framew...@googlegroups.com
You're probably missing this in your controller:

<cffunction name="setPersonService">
<cfargument name="personService">
<cfset variables.services.person = arguments.personService>
</cffunction>

That tells FW/1 & DI/1 that your controller wants personService (i.e., services/person.cfc) injected into it.

Sean
signature.asc

Ram

unread,
Aug 21, 2014, 10:40:50 PM8/21/14
to framew...@googlegroups.com
Thank you very much. 
I think I need to call the method (savePerson()) in person.cfc after this code, which insert the data into table in the database.

Sean Corfield

unread,
Aug 21, 2014, 10:50:20 PM8/21/14
to framew...@googlegroups.com
The setPersonService function I provided will tell FW/1 & DI/1 to inject the person service. That will solve the error you ran into.

You are already calling variables.services.person.savePerson() in your controller's person method - although you will need to add argumentCollection = rc if you want items passed to the service.

I would STRONGLY recommend you work carefully, step-by-step through the Getting Started guide since this will explain much of what you're clearly struggling with:


It also explains the conventions that are normally used with FW/1: you'd normally have a model folder containing your services folder (and a beans folder).

You'll find life MUCH easier if you follow the documentation and get those examples working first.

Sean

--
--
FW/1 on RIAForge: http://fw1.riaforge.org/
 
FW/1 on github: http://github.com/framework-one/fw1
 
FW/1 on Google Groups: http://groups.google.com/group/framework-one
---
You received this message because you are subscribed to the Google Groups "framework-one" group.
To unsubscribe from this group and stop receiving emails from it, send an email to framework-on...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sean Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)



signature.asc

Ram

unread,
Aug 21, 2014, 11:06:28 PM8/21/14
to framew...@googlegroups.com
Sure. Thanks a lot. I was reading the documentation and did hello series examples for last 3 days.  So I used the method variables.services.person.savePerson(). 
It did not worked  for me.
I read  some place accessing like: application.services.Person.savePerson(form). I am working with version.2.5 on windows 7.
 I will work on this tomorrow. I really appreciate your help.

Sean Corfield

unread,
Aug 22, 2014, 11:50:37 AM8/22/14
to framew...@googlegroups.com
On Aug 21, 2014, at 8:06 PM, Ram <tbu...@gmail.com> wrote:
> Sure. Thanks a lot. I was reading the documentation and did hello series examples for last 3 days. So I used the method variables.services.person.savePerson().
> It did not worked for me.

The error you showed indicated services was not set in variables scope. Adding the setter I showed should have solved that but you'd be better off following the conventions of FW/1 and having:

/model
/services
person.cfc

in your file system and using property-based injection (and cfscript) in your controllers:

component accessors=true {
property personService;

function person( rc ) {
if ( structKeyExists( rc, "savePerson" ) {
variables.personService.savePerson( argumentCollection = rc );
signature.asc

Ram

unread,
Aug 22, 2014, 12:24:09 PM8/22/14
to framew...@googlegroups.com
I have tested today with the code you provided. It works like a charm. !!!  
Sure. I will follow the conventions. A big relief for weekend!.

Thanks, Ram

Sean Corfield

unread,
Aug 22, 2014, 12:39:13 PM8/22/14
to framew...@googlegroups.com
On Aug 22, 2014, at 9:24 AM, Ram <tbu...@gmail.com> wrote:
> I have tested today with the code you provided. It works like a charm. !!!

Yay!

> Sure. I will follow the conventions. A big relief for weekend!.

The nice thing about following the conventions is that it will be easier for you to move to FW/1 3.0 (currently in beta) where you can just let FW/1 auto-create the DI/1 bean factory (so you could delete your current setupApplication() method).
signature.asc
Reply all
Reply to author
Forward
0 new messages