[ColdBox 4.1], [ColdFusion 9.1] Dynamic values in formula attribute of cfproperty

Hi

I have a persistent component which has a custom property which looks like this:

property name=“DISPLAY_IN_DIRECTORY_LB” setter=“false” formula="
select CASE WHEN DISPLAY_IN_DIRECTORY_NB = 1 THEN ‘Public’ ELSE ‘Private’ END from JOU_V_REV_PECO vrp where vrp.peco_ky = peco_ky
";

This works fine.

However, I want to replace the words ‘Private’ and ‘Public’ with strings from my language resource bundle, eg, “#getResource(“template.public”)#”. As soon as I do this I run into a, “Expression in cfproperty value must have a constant value” error.

I have tried loading the strings into local variables in the init() method and using the local variable instead, but I get the same error, no doubt for the same reason.

Does anyone know how I can achieve this?

Sorry you can’t. Not that way anyway.

The best thing to do is to use the preLoad event and set that field manually.

Hi Andrew

Thanks for the reply.

However, I can’t see how that would work. If I load the i18n values into variables in the preLoad() function of my handler, and then try to use those variables in the formula attribute of cfproperty, I will surely hit the same problem, no?

Did I mis-understand?

~~michael

No what I mean is use a property with no persistence, use the preLoad to load what you want and store it into that property. formula’s can’t contain variables. Hence the message constant value. If you’re not sure look it up in the ColdFusion docs to see what I mean with formula’s.