Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • andrew shearer 510 posts 659 karma points
    Aug 27, 2010 @ 01:35
    andrew shearer
    0

    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

  • andrew shearer 510 posts 659 karma points
    Aug 27, 2010 @ 01:38
    andrew shearer
    0

    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.

     

  • andrew shearer 510 posts 659 karma points
    Aug 27, 2010 @ 02:51
    andrew shearer
    0

    just confirmed the Save funtion seems to work fine, so its only the loading thats not.

    :(

     

  • andrew shearer 510 posts 659 karma points
    Aug 30, 2010 @ 05:39
    andrew shearer
    0

    anyone able to help?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Aug 30, 2010 @ 06:53
    Jeroen Breuer
    0

    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

  • andrew shearer 510 posts 659 karma points
    Aug 30, 2010 @ 22:08
    andrew shearer
    0

    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


  • andrew shearer 510 posts 659 karma points
    Aug 31, 2010 @ 00:52
    andrew shearer
    0

    even a database profiler trace shows the correct data being loaded for the correct cmsPropertyData record.. i must be so close.

     

  • andrew shearer 510 posts 659 karma points
    Aug 31, 2010 @ 01:32
    andrew shearer
    0

    error seems to be:

     

    Version    '((umbraco.cms.businesslogic.datatype.DefaultData)(Data)).Version' threw an exception of type 'System.InvalidOperationException'    System.Guid {System.InvalidOperationException}

  • andrew shearer 510 posts 659 karma points
    Sep 02, 2010 @ 00:37
    andrew shearer
    0

    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.

    :)

  • andrew shearer 510 posts 659 karma points
    Sep 02, 2010 @ 00:42
    andrew shearer
    1

    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!

  • Stephan Lonntorp 195 posts 212 karma points
    Mar 03, 2011 @ 09:43
    Stephan Lonntorp
    0

    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!

Please Sign in or register to post replies

Write your reply to:

Draft