Copied to clipboard

Flag this post as spam?

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


  • Tony Pellegrino 2 posts 21 karma points
    May 15, 2012 @ 18:13
    Tony Pellegrino
    0

    Import to uComponents XPath CheckBoxList

    I'm trying to use CMSImport to map data to an XPath CheckBoxList from uComponents but cannot for the life of me figure out how to get the values of the existing CheckBoxes. I've tried pulling them out as PreValues but the only result I can get from that is: {"XPath":"//Color","UseXml":true,"UseIds":true} which is the path definition of the CheckboxList, but not the values. Any thoughts on how to use this path definition to pull the actual checkbox values? The code I'm using is below. Thanks,

    SortedList preValues = PreValues.GetPreValues(dataTypeDefinitionID);
    
    foreach (DictionaryEntry entry in preValues)
    {
         PreValue prevalue = entry.Value as PreValue;
         throw new System.ArgumentException(prevalue.Value.ToString(), "");
    }
    
  • Tom Fulton 2030 posts 4998 karma points c-trib
    May 15, 2012 @ 18:22
    Tom Fulton
    1

    Hi Tony,

    The available nodes based on your XPath aren't stored anywhere within the datatype, they are searched for at runtime when you open a page with your datatype.

    If you check out the source code, you can see it's using uQuery.GetNodesByXPath(this.options.XPath).ToNameIds();

    uQuery is part of uComponents - so best recommendation might be to reference the uComponents DLL in your project here and use the same method they are using.

    HTH,
    Tom 

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    May 15, 2012 @ 18:41
    Lee Kelleher
    0

    Hi Tony,

    When you say that you are using CMSImport to map the data... where are you getting the data from?

    From looking at your config of the XPathCheckBoxList, you are using XML and storing the NodeIds; which means that you would need to get your data into a suitable format (building it up as a string), so that it is ready for importing... e.g.

    <XPathCheckBoxList>
        <nodeId>1111</nodeId>
        <nodeId>2222</nodeId>
        <nodeId>3333</nodeId>
    </XPathCheckBoxList>

    As Tom says, the JSON string from the data-type's config isn't used against the values.

    Cheers, Lee.

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    May 15, 2012 @ 19:58
    Richard Soeteman
    1

    Hi Tony,

    Great to see the answers of all. By default this datatype isn't supported by CMSImport. What you need to do is deliver the information in a format so the XPathCheckboxList understands it. this can either be the complete xml as Lee described. CMSImport handles this different for the Datatypes that are supported. The API comes with a FieldAdapter that basically inspects the documentproperty where it's mapped against and thansform the incoming data to the recuired format. So in this case you could write your own FieldAdapter that takes a comma seperated list of node id's and convert that to the xml format Lee mentioned.

    Below an example that I use myself for the tags datatype. You see that the FieldAdapter derives from the IFieldAdapter interface. Then it will be picked up in the Import process.The DataTypeId property is the GUID that you see when you open the dataype in Umbraco. This needs to corresponent with the DataTypeId for the XpathCheckBoxList in your case. Then it will be picked up automatically and you can implement the transformation in the Parse method

        /// <summary>
        /// Field Adapter for the default Tags Datatype
        /// </summary>
        public class TagsFieldAdapter :IFieldAdapter
        {
            public Guid DataTypeId
            {
                get { return new Guid("4023e540-92f5-11dd-ad8b-0800200c9a66"); }
            }
    
            /// <summary>
            /// Use the TagHelper to parse and store the data
            /// </summary>
            public object Parse(object value, umbraco.cms.businesslogic.property.Property property, FieldAdapterOptions fieldAdapterOptions)
            {
                string tagGroup = string.Format("{0}", property.GetPreValue());
                return TagHelper.ParseTagValues(value, property,tagGroup);
            }
        }
    

    FieldAdapters are also documented in the CMSImport manual. http://cmsimport.com/media/2940/cmsimport%20manual.pdf

    Cheers,

    Richard

Please Sign in or register to post replies

Write your reply to:

Draft