Using the PageInfoPicker widget in a custom visitor group criterion

 

Hi,

I'm trying to create a custom visitor group critirion that has a page picker property like in the built in Visited page criterion. I added a PageInfo property to my model and decorated that with the Required and DojoWidget attributes like below: 

[DojoWidget(WidgetType = "epi.cms.form.PageInfoPicker")]
[Required]
public virtual PageInfo SelectedPage { get; set; }

By doing this I'm able to get the page picker to show and to select a page as well as to save the custom criterion. I can see that it gets saved to the DB. But when I open the visitor group for editing again in the admin view, the SelectedPage-property is empty. Is there something else I need to do in order to make this work? Is it at all possible to use the built in PageInfoPicker widget? 

Thanks!

#88147 Jul 03, 2014 7:54
  • Shamrez Iqbal
    Member since: 2006
     

    I was having the same problem when trying to do this and had to use lots of reflection and analysis to figure out what was going on, i looked at the controller for the visitor groups, I looked at the dynamic datastore implementation and then I realized that the problem was caused by the PageInfo class.

    The problem is two fold, first of only the PageGuid is stored in the database, but unless you call the ValidatePage the way it is done in EPIServers own criterias, the PageGuid isn't set, and so you basically save an empty Guid to the database. Now the second part of the problem is when trying to replicate the validation, it goes something like

    if(SelectedPage != null && !SelectedPage.Validate())

    and in the Validate method the PageGuid is set but the problem when trying to replicate it is that the method is internal so I had to use reflection to use the method something like: 

    MethodInfo mi = SelectedPage.GetType().GetMethod("ValidatePage", BindingFlags.Instance| BindingFlags.NonPublic);
                    var result = mi.Invoke(Page, new object[]{});

    which then forces the validation, which updates your PageGuid and thus persists the Page in the database.

    #112598 Oct 30, 2014 20:54