cfproperty default attribute should preserve types and support complex types
Description
Attachments
- 14 Apr 2025, 07:38 am
- 04 Apr 2025, 07:55 am
- 04 Apr 2025, 07:55 am
Activity
Michael Offner 28 April 2025 at 19:32
after small correction (bypass LDEV-5547) the test cases is passing now.
Michael Offner 28 April 2025 at 19:02(edited)
everything seem to work, only problem is that the compiler itself converts the values to string
so this default
are interpreted as string
property name="name" type="string" getter="true" setter="true" default="lucee";
property name="id" type="numeric" getter="true" setter="true" default=123;
property name="luceeRocks" type="boolean" getter="true" setter="true" default=true;
but when i do this
property name="name" type="string" getter="true" setter="true" default="lucee";
property name="id" type="numeric" getter="true" setter="true" default="#123#";
property name="luceeRocks" type="boolean" getter="true" setter="true" default="#true#";
they are correctly handled as string,number and boolean, but the compiler should handle both of them in the same way.
so this is an issue unrelated to this ticket.
I have created a ticket for this
https://luceeserver.atlassian.net/browse/LDEV-5547
Zac Spitzer 14 April 2025 at 07:38
simple defaults are still string?
https://github.com/lucee/Lucee/commit/aa32e2fb7257155f39a6b9d24f7a5bc502ec01ca
component accessors=true{
property name="name" type="string" getter="true" setter="true" default="lucee";
property name="id" type="numeric" getter="true" setter="true" default=123;
property name="luceeRocks" type="boolean" getter="true" setter="true" default=true;
function getInstance(){
return this;
}
};
Michael Offner 4 April 2025 at 09:05
Michael Offner 4 April 2025 at 08:08
the generated java code for this looks like this
try {
var7.setDefault(Caster.toString(LiteralArray.call(var1, new Object[0])));
var7.setSetter(true);
var7.setGetter(true);
var7.setType("Array");
var7.setName("MyArray");
var7.doStartTag();
if (var7.doEndTag() == 5) {
throw Abort.newInstance(0);
}
} finally {
((PageContextImpl)var1).reuse(var7);
}
and when i set for example application.susi
as default, it looks like this
try {
var7.setDefault(Caster.toString(var1.applicationScope().get(KeyConstants._SUSI)));
var7.setSetter(true);
var7.setGetter(true);
var7.setType("Array");
var7.setName("MyArray");
var7.doStartTag();
if (var7.doEndTag() == 5) {
throw Abort.newInstance(0);
}
} finally {
((PageContextImpl)var1).reuse(var7);
}
so the limitation comes with casting it to String and setDefault
only accepting a String as an input, i also see that the Property
interface defines thispublic String getDefault();
this is something we can only address with Lucee 7
Details
Details
Assignee
Reporter
Labels
New Issue warning screen
Before you create a new Issue, please post to the mailing list first https://dev.lucee.org
Once the issue has been verified, one of the Lucee team will ask you to file an issue
If you set a default that is an array in a property, it ignores it. for example:
component accessors=true{ property name="MyArray" type="Array" getter="true" setter="true" default="#[]#"; }
p = new TestDefaultProp(); if(!IsArray(p.getMyArray())){ throw("MyArray Should be an initialized Array"); }