im working on the DataEditor of a new custom datatype. It implements IDataEditor as required but im having trouble getting it to load content from the umbraco db.
from what i can work out, the Data for the custom control is automatically loaded and saved because of this implementation in the the DataType (IDataType) class:
public override IData Data { get { if (_baseData == null) _baseData = new umbraco.cms.businesslogic.datatype.DefaultData(this); return _baseData; } }
what am i missing? why wouldn't this be working? thanks
NB i manually put some data in the cmsPropertyData data for the custom control to load. I looked through the cmsDocument, cmsDataType, cmsPropertyType, and cmsDataTypePreValues table to ensure im dealing with the correct propertyData record.
Version '((umbraco.cms.businesslogic.datatype.DefaultData)(Data)).Version' threw an exception of type 'System.InvalidOperationException' System.Guid {System.InvalidOperationException}
Sorted this out. The problem here is that i was trying to use Data straight after it had been passed into the constructer (that seems logical, right?).
public MyCustomDataType(umbraco.interfaces.IData Data, string Configuration) { _data = Data; ...
But it turns out Data is not actually populated until after this constructor. It is not available for use until the OnInit() method.
Im sure this must break a golden rule of best programming practise., but can’t think of exactly what that would be right now…
I just thought I’d post this up for anyone else battling with Umbraco.
Thinking about how Umbraco must work under the hood, the data must be loaded in one statement and then provided to each control/data type on the page. (although, an sql profiler trace doesn’t suggest it actually works like this).
That was the only conclusion I could come up with for why “Data” is not actually populated when it is passed into the constructor.
I had the same issue, and this helped me solve it. It's funny that the data isn't available in the constructor. the object itself is fine, but the IData.Value / DefaultData.Value is null, and that's funky.
custom datatype
im working on the DataEditor of a new custom datatype. It implements IDataEditor as required but im having trouble getting it to load content from the umbraco db.
public myControlDataEditor(umbraco.interfaces.IData Data, string Configuration)
{
_data = Data;
this._configuration = Configuration;
}
from what i can work out, the Data for the custom control is automatically loaded and saved because of this implementation in the the DataType (IDataType) class:
public override IData Data
{
get
{
if (_baseData == null)
_baseData = new umbraco.cms.businesslogic.datatype.DefaultData(this);
return _baseData;
}
}
what am i missing? why wouldn't this be working? thanks
NB i manually put some data in the cmsPropertyData data for the custom control to load. I looked through the cmsDocument, cmsDataType, cmsPropertyType, and cmsDataTypePreValues table to ensure im dealing with the correct propertyData record.
just confirmed the Save funtion seems to work fine, so its only the loading thats not.
:(
anyone able to help?
I don't know what is wrong, but you could compare your code with the the example Tim wrote: http://www.nibble.be/?p=62 or look at the source code of http://ucomponents.codeplex.com/SourceControl/list/changesets which can also be usefull.
Jeroen
thanks Jeroen. i think thats the code i used as the basis of my custom datatype, but i'll def take another look and see if i missed anything :) thanks
even a database profiler trace shows the correct data being loaded for the correct cmsPropertyData record.. i must be so close.
error seems to be:
Version '((umbraco.cms.businesslogic.datatype.DefaultData)(Data)).Version' threw an exception of type 'System.InvalidOperationException' System.Guid {System.InvalidOperationException}
Sorted this out. The problem here is that i was trying to use Data straight after it had been passed into the constructer (that seems logical, right?).
public MyCustomDataType(umbraco.interfaces.IData Data, string Configuration)
{
_data = Data;
...
But it turns out Data is not actually populated until after this constructor. It is not available for use until the OnInit() method.
Im sure this must break a golden rule of best programming practise., but can’t think of exactly what that would be right now…
I just thought I’d post this up for anyone else battling with Umbraco.
:)
Thinking about how Umbraco must work under the hood, the data must be loaded in one statement and then provided to each control/data type on the page. (although, an sql profiler trace doesn’t suggest it actually works like this).
That was the only conclusion I could come up with for why “Data” is not actually populated when it is passed into the constructor.
Umbraco 1 My time 0
Hope this info helps someone else!
I had the same issue, and this helped me solve it. It's funny that the data isn't available in the constructor. the object itself is fine, but the IData.Value / DefaultData.Value is null, and that's funky.
Thanks!
is working on a reply...