[ColdBox 3.5.2] When to use rc. vs event.getValue() ?

Hi, I’m confused regarding the several different ways to pull values into handler methods. Which of these is correct?

<cfset var ecCartService = getPlugin(‘ioc’).getBean(‘EcCartService’) />
<cfset rc.msg = ecCartService.addItem(
productID = arguments.rc.productID,
qty = arguments.rc.qty,
remarks = arguments.rc.remarks
)
/>

vs

<cfset var ecCartService = getPlugin(‘ioc’).getBean(‘EcCartService’) />
<cfset rc.msg = ecCartService.addItem(
productID = arguments.event.getValue(“productID”),
qty = arguments.event.getValue(“qty”,“1”),
remarks = arguments.event.getValue(“remarks”,"")
)
/>

And, where I’m setting rc.msg, should I instead be using event.setValue(“msg”, msg) ?

Thanks,
-Ryan

I have the same questions. event.getvalue() or refer to rc directly? What’s the right approach or are both valid?

aVariable = event.getValue(“keyName”, “defaultValue”); // has an advantage of assigning defaultValue to aVariable, if keyName does not exist.

If you know keyName is previously defined, then you can simply use rc.keyName to get its value.
aVariable = rc.keyName;

Great thanks!

Hi

Both accomplish the same. GetValue() gives you the option to pass a default value. That’s about it. In terms of what is best practice. I would recommend direct access to the structure. Manipulating structures natively will always be faster than method calls.

Just be pragmatic.

Thank you for the quick and helpful replies! This group is awesome! :slight_smile: