overriding a function in coldfusion

461 Views Asked by At

I have a function named as OnSubmit in two CFCs,

one is BASE.cfc and other is PageUsed.cfc . the function is different in base.cfc and pageused.cfc , but the name is name and arguments are same.

there is a third CFC named as UserObject.cfc invoked by passing a method name as Basic which returns the PageUsed.cfc object and method is called OnSubmit,

it should basically call the Onsubmit function in the pageUsed but it is calling the Base.cfc OnSubmit Function

what is going wrong

any idea?

Do i need to use SUPER, but super is used for some other purpose as i read

1

There are 1 best solutions below

2
On

Components often extend other components and you do this explicitly in the component declaration.

<component extends="some.other.component">

In your case if you are doing <component name="pageused" extends="base"> then in the pageused comonent you may have.

function onSubmit() {

}

Calling onSubmit like pageUsed.onSubmit() will run that function. If you want to run the onSubmit inside the base you could add the following to pageused.

function onSubmit() {
    super.onSubmit(); //Calling onSubmit in base.cfc
}

What is confusing about your question is this part:

there is a third CFC named as UserObject.cfc invoked by passing a method name as Basic which returns the PageUsed.cfc object and method is called OnSubmit,

I get there is a userObject.cfc but can you share the code of where that is because it appears that that part is probably not working how you think it is. Especially confusing is you are passing a name "basic" but returning "pageUsed". Why wouldn't it return basic?