Ram
Ram

Reputation: 7

Form action call to insert data to database in Framework 1

I am learning Framework1 and tried to do a simple ColdFusion program to insert data into 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 will call the file in services folder to run insert statement via controller?

Upvotes: 1

Views: 695

Answers (1)

Joey
Joey

Reputation: 381

I have a feeling you might be missing get/set to the Person Service. Also make sure you've got the service declared in the beans.xml.cfm

controllers/person.cfc

<cffunction name="setPersonService" access="public" output="false">
    <cfargument name="personService" type="any" required="true" />
    <cfset variables.personService = arguments.personService />
</cffunction>
<cffunction name="getPersonService" access="public" returntype="any" output="false">
    <cfreturn variables.personService />
</cffunction>

assets/config/beans.xml.cfm

<bean id="personService" class="myapp.services.Person" singleton="true">
</bean>

Edit: Oh I just realised this question was answered on the FW/1 groups

Upvotes: 1

Related Questions