Developer forum

Forum » Development » Trying to extend with NavigationProvider

Trying to extend with NavigationProvider

Kim SĂžjborg Pedersen
Reply

Inspired by this thread http://developer.dynamicweb-cms.com/forum.aspx?PID=48&ThreadID=23903 I am trying to extend my Navigation Menu

I have this keep it simple code, that makes an exception on the " nodeList.Add(eni);" line

[AddInOrder(-1)]

    public class ExtendedMenu : NavigationProvider
    {
        public override void ProcessTree(RootNavigationItem rootNode, Dynamicweb.Frontend.XmlNavigation.NavigationType navigationType)
        {
            if (navigationType == Dynamicweb.Frontend.XmlNavigation.NavigationType.Menu)
            {

                List<NavigationItem> nodeList = rootNode.ChildNodes;
                int elements = nodeList.Count;

                for (int i = 0; i < elements; i++)
                {
                    ExtendedPageNavigationItem eni = new ExtendedPageNavigationItem
                    {
                        ContainsProducts = "false",
                    };

                    nodeList.Add(eni);
                }

            }
        }
    }

    public class ExtendedPageNavigationItem : PageNavigationItem
    {
        [AddInName("ContainsProducts")]
        public string ContainsProducts { get; set; }
    }

 

And the exception is:

 

[NullReferenceException: Object reference not set to an instance of an object.]
   Dynamicweb.Frontend.NavigationProviders.GroupNavigationProvider.MakeGroupTree(Page page, NavigationItem parentNode) +69
   Dynamicweb.Frontend.NavigationProviders.GroupNavigationProvider.Process(NavigationItem node) +437
   Dynamicweb.Frontend.NavigationProviders.GroupNavigationProvider.ProcessTree(RootNavigationItem rootNode, NavigationType navigationType) +47
   Dynamicweb.Frontend.XmlNavigation.XML(Int32 ParentID, Int32 StartLevel, Int32 StopLevel, Expand expand, Int32 areaID) +1432
   Dynamicweb.Frontend.XmlNavigation.GetNavigationHtml(Int32 ParentID, Int32 StartLevel, Int32 StopLevel, Expand ExpandMode, String NavigationName, String XsltPath, Int32 AreaID, Boolean SitemapMode, NameValueCollection settings, NameValueCollection attributes, IncludeMode mode) +140
   Dynamicweb.Frontend.XmlNavigation.GetNavigationHtml(NameValueCollection settings, NameValueCollection attributes) +1519
   Dynamicweb.Frontend.XmlNavigation.GetNavigationHtml(DynamicElement d) +496
   Dynamicweb.Frontend.XmlNavigation.ParseNavigationTags(Template t, Layout l) +147
   Dynamicweb.Frontend.PageView.SetPageTemplateValues() +10036
   Dynamicweb.Frontend.PageView.Output() +780
   Dynamicweb.Frontend.PageviewControl.ParseControls() +55
   Dynamicweb.Frontend.PageviewControl.OnInit(EventArgs e) +86
   System.Web.UI.Control.InitRecursive(Control namingContainer) +134
   System.Web.UI.Control.AddedControl(Control control, Int32 index) +191
   System.Web.UI.ControlCollection.Add(Control child) +86
   Dynamicweb.Admin.DefaultAspx.Page_Load(Object sender, EventArgs e) +60
   System.Web.UI.Control.OnLoad(EventArgs e) +92
   System.Web.UI.Control.LoadRecursive() +54
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

 

UPDATE:

It don't seems like the rootNode contains any ecom based items, and that was my goal in the code above so I don't need a soultion on this exception.


Replies

 

You must be logged in to post in the forum