Cannot find CriterionPropertyEditor?

Vote:
 

Hi!

I'm trying to create my own criteria using this article:
https://world.optimizely.com/documentation/developer-guides/CMS/personalization/developing-custom-visitor-group-criteria/

But I cannot find any reference to CriterionPropertyEditor?

[CriterionPropertyEditor(SelectionFactoryType = typeof(MatchStringType))]

Gives me error that CriterionPropertyEditor cannot be found are you missing reference? I what namespace is CriterionPropertyEditor located?

Thanks!

/Kristoffer

#278014
Apr 07, 2022 16:46
Vote:
 

Hmmm..... Looking here: https://world.optimizely.com/csclasslibraries/cms/EPiServer.Personalization.VisitorGroups.CriterionPropertyEditorAttribute?version=12

Should it be "CriterionPropertyEditorAttribute" (in the namespace EPiServer.Personalization.VisitorGroups) instead of "CriterionPropertyEditor"?

#278073
Apr 07, 2022 22:25
Vote:
 

Hi,

The CriterionPropertyEditor attribute is new to CMS 12 so, if the 11.20.x tag you've added is correct and you're working on v11, you don't need that attribute. The documentation for v11 is here:

https://world.optimizely.com/documentation/developer-guides/archive/cms/personalization/developing-custom-visitor-group-criteria/ 

#278114
Apr 08, 2022 8:15
Vote:
 

Thanks Paul!

#278115
Apr 08, 2022 8:18
Vote:
 

No problem.

For the sake of future-proofing the answer, I should point out that the newer version of that documentation for v11 can be found here:

https://docs.developers.optimizely.com/content-cloud/v11.0.0-content-cloud/docs/developing-custom-visitor-group-criteria 

#278116
Apr 08, 2022 8:32
Vote:
 

Hmm, doing this:

[DojoWidget(WidgetType = "dijit.form.FilteringSelect", SelectionFactoryType = typeof(EnumSelectionFactory<MatchStringType>))]
public MatchStringType MatchType { get; set; }

gives me this:

[NullReferenceException: Object reference not set to an instance of an object.]
   EPiServer.Personalization.VisitorGroups.DojoHtmlExtensions.DojoDropDownFor(HtmlHelper`1 html, PropertyInfo p, Object htmlAttributes, String label, String labelCssClass, LabelPosition labelPosition, DojoWidgetAttribute attr) +112
   EPiServer.Personalization.VisitorGroups.DojoHtmlExtensions.DojoEditorFor(HtmlHelper`1 html, PropertyInfo propertyInfo, Object htmlAttributes, String label, String labelCssClass, LabelPosition labelPosition) +224
   ASP.episerver_cms_views_shared_editortemplates_object_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in D:\Projekt\Direktronik\Direktronik.se\Direktronik.Web\episerver\CMS\Views\Shared\EditorTemplates\Object.ascx:38
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +116
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +131
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +270
   System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +74
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +131
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +9530

EnumSelectionFactory:

public class EnumSelectionFactory<TEnum> : ISelectionFactory
    {
        public IEnumerable<ISelectItem> GetSelections(
            ExtendedMetadata metadata)
        {
            var values = Enum.GetValues(typeof(TEnum));
            foreach (var value in values)
            {
                yield return new SelectItem
                {
                    Text = this.GetValueName(value),
                    Value = value 
                };
            }
        }

        private string GetValueName(object value)
        {
            var staticName = Enum.GetName(typeof(TEnum), value);

            if (staticName != null)
            {
                string localizationPath = string.Format(
                    "/property/enum/{0}/{1}",
                    typeof(TEnum).Name.ToLowerInvariant(),
                    staticName.ToLowerInvariant());

                string localizedName;
                if (LocalizationService.Current.TryGetString(
                    localizationPath,
                    out localizedName))
                {
                    return localizedName;
                }
            }

            return staticName;
        }
    }

Any ideas?

/Kristoffer

#278117
Apr 08, 2022 8:41
Vote:
 

Found the answer here!

https://world.optimizely.com/forum/developer-forum/CMS/Thread-Container/2016/5/criterion-null-reference-when-using-selectionfactorytype/

#278118
Apr 08, 2022 9:08
Vote:
 

Unless you're doing something special, you shouldn't need to create a new EnumSelectionFactory as there's already one ready-to-use in EPiServer.Web.Mvc.VisitorGroups.EnumSelectionFactory.

#278119
Apr 08, 2022 9:31
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.