Adding properties with getters and setters to a component after instantiation


Is there any way to do what Ben is doing in this blog post with Lucee?

He adds properties with the getters after the component was created.

We have tried to do this:

var testing = new testing();
			, 'name': 'awesomeProperty'
			, 'position': '02'
			, 'type': 'any'
			, 'validate': 'string'
			, 'validateparams': '{minLength=3, maxLength=5}'
			, 'getter': true
			, 'default': 'boom'


After reading Ben’s article I came to the conclusion that modifying the component metadata does not actually produce usable getters in the component (as illustrated by his attempt to use getBust() in his code example and as identified in the last comment he made on that post). Not to mention this is a 7 year old post and the point of which seems to illustrate serializeJSON()'s ability to bypass scope security in whatever version of CF he was using then… so I’m not sure that even applies anymore (though knowing Adobe, it probably still does is ACF).

That said, perhaps if you elaborated the use case you’re trying to solve we can probably point you in a better direction than trying to hack the metadata.

– Denny


The use case for us is more of a convenience factor to make things easier for us. Basically what we are doing is parsing EDI files. Each EDI file has lots of possible segments. For example an EDI 210 version 4010 file has something like 40-50 segments and each segment has several fields of which there are specific types, maximum uses, min-length, max-length, etc. What we have been doing is creating a CFC for each segment with properties for each field like below manually:

ISA Segment

import "Models.EDI.Segments.AbstractSegment";
component accessors="true" extends="AbstractSegment" displayname="InterchangeControlHeader" {
	property position="01" id="I01" name="AuthorizationInfoQualifier" validate="string" validateParams="{minLength=2, maxLength=2}";
	property position="02" id="I02" name="AuthorizationInfo" validate="string" validateParams="{minLength=10, maxLength=10}";
	property position="03" id="I03" name="SecurityInfoQualifier" validate="string" validateParams="{minLength=2, maxLength=2}";
	property position="04" id="I04" name="SecurityInfo" validate="string" validateParams="{minLength=10, maxLength=10}";
	property position="05" id="I05" name="InterchangeSenderIDQualifier" validate="string" validateParams="{minLength=2, maxLength=2}";
	property position="06" id="I06" name="InterchangeSenderID" validate="string" validateParams="{minLength=15, maxLength=15}";
	property position="07" id="I05" name="InterchangeReceiverIDQualifier" validate="string" validateParams="{minLength=2, maxLength=2}";
	property position="08" id="I07" name="InterchangeReceiverID" validate="string" validateParams="{minLength=15, maxLength=15}";
	property position="09" id="I08" name="InterchangeDate" type="date" formatType="date" validate="date";
	property position="10" id="I09" name="InterchangeTime" type="time" formatType="time" validate="string" validateParams="{minLength=4, maxLength=4}";
	property position="11" id="I10" name="InterchangeControlStandardsID" validate="string" validateParams="{minLength=1, maxLength=1}";
	property position="12" id="I11" name="InterchangeControlVersion" validate="string" validateParams="{minLength=5, maxLength=5}";
	property position="13" id="I12" name="InterchangeControlNumber" validate="string" validateParams="{minLength=9, maxLength=9}";
	property position="14" id="I13" name="AcknowledgementRequested" validate="string" validateParams="{minLength=1, maxLength=1}";
	property position="15" id="I14" name="UsageIndicator" validate="string" validateParams="{minLength=1, maxLength=1}";
	property position="16" id="I15" name="ComponentElementSeparator" validate="string" validateParams="{minLength=1, maxLength=1}";

This is very time consuming and creates a lot of files so we were looking for a way to use an XML file for automatically either creating components on the fly or automatically adding the properties to a nearly blank CFC using attributes on each XML tag.

What would be really cool is just to create a string representation of a component with all the properties dynamically and then instantiate but I have not been able to figure out how to do that. I figured there must be a way to add properties after the component has been instantiated but it looks like that might not be possible either.