November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
you might need to put a json converter on type of your list property for cities. I ran into this with the url property where when you save, the values would jsut disappear. Try putting a JsonConverter(typeof(xxx)) on type of your Cities properties.
Hi Joshua,
I have tried what you suggested, implemented the converter based on that implementation https://blog.bitscry.com/2017/08/31/single-or-array-json-converter/ and then decorated my property like:
[JsonConverter(typeof(SingleOrArrayConverter<string>))] public IList<string> Cities { get; set; }
But still no luck and same behavior.
Greg, I tried this with Alloy site. Changing the editor for the Cities list to the Alloy StringListEditorDescriptor gets a "working" edit but naturally it is displaying the textarea editor where you put the "city name" on a separate line.
[EditorDescriptor(EditorDescriptorType = typeof(Business.EditorDescriptors.StringListEditorDescriptor))] public IList<string> Cities { get; set; } = new List<string>();
It isn't what you are trying to achieve, but maybe a hint that you should create own editor to make it work. Maybe the editor what you get is just a side effect of something.
I tested also with changinig the IList<string> to ICollection<string> and then the default editor only showed properties for the ICollection: Count and IsReadOnly
Hi Antti, if you are talking about having that property with no use of PropertyList it works nicely then you don't even need any descriptor with IList<string> properties, but here in connection with PropertyList it fails on edit data.
It might be that editor I get now is kind of side effect of something else.
Hi Greg, no I meant that you only use the stringlisteditor from Alloy and decorate your Cities property with as shown above code. You still have your Locations and the same code that you originally posted. You just change the editor for the Cities list. UI works ok and you can edit existing cities list. The only downside is that the editor for the cities list is now textarea where you write each city on a separate line. In your code you can still do foreach to the locations list and foreach for the cities list.
I also tested with changing the Cities items to custom object like:
public class City { public string Name { get; set; } }
[EditorDescriptor(EditorDescriptorType = typeof(CollectionEditorDescriptor<City>))] public IList<City> Cities { get; set; } = new List<City>();
This also work, only downside is the editor experience when editing the items in cities. Also when looking the all properties view of the page having the locations property, the editor displays the locations property something like this:
Finland [object Object], [object Object] Sweden [object Object]
Alright, I will then try to get the StringListEditorDescriptor from Alloy and decorate Cities property. The fact it is textarea is still acceptable, since I assume in most of the cases, pages will be handled anyway only by scheduled job.
As long I can iterate locations and cities from code it is fine. I wanted to avoid idea of creating separate block types for locations since it requires more complex logic to use later the data from it and PropertyList looked much more friendly in that case.
Will let you know if it worked when I find some time during weekend, thanks for now!
Hi Antti, it works! Please take the credit :)
As you said the only negative thing it is showing cities as textarea, each value in separate line, but I would say it is acceptable in that case.
However I would like to hear from someone from Epi core team if that is the way or we missed some other recommended approach.
Greg, maybe it would be good idea to create a developer ticket about this. Maybe there is currently a bug and it will get fixed or maybe a feature the development team can easily implement.
I have created support ticket as well, will keep you informed how it ended
Got an answer to my ticket:
Hi Grzegorz, The PropertyList was designed primarily to be used with simple types such as int, string, etc and the “out-of-the-box experience” will only cater for such types. If you want to use a more complex type as described in the forum thread, both responsible for making sure that the type can be serialized (using Json.NET) and that it’s properly decorated for editing. I hope this will clarify your concern. Thanks, Trung Support Team
We have already fixed that issue. It will be released in 11.4.2 or 11.5.0.
Thanks a lot Bartek!
Looking forward for the release, any kind of estimate when it will come?
And Bartosz one more thing, what will be the official recommended way how to handle such cases? do we really need still to have that SingleOrArrayConverter class with decorating property with the attributes like
public class Location { public string Country { get; set; } [JsonProperty] [JsonConverter(typeof(SingleOrArrayConverter<string>))] public IList<string> Cities { get; set; } }
or this is not needed anymore with your fix?
Btw 11.5 has been already released and I have still that issue on Alloy with latest
Ah or actually you are probably saying about EPiServer.CMS.UI package version release
Yes, sorry I should have been more specific. I meant EPiServer.CMS.UI - I'm from the UI team hence the misunderstanding :)
About your question - you don't need any attributes.
public class Location { public string Country { get; set; } public IList<string> Cities { get; set; } } [PropertyDefinitionTypePlugIn] public class LocationListProperty : PropertyList<Location> { }
and then
[EditorDescriptor(EditorDescriptorType = typeof(CollectionEditorDescriptor<Location>))] public virtual IList<Location> Locations { get; set; }
in your page model would work fine.
Awesome, I thought so we do not need any extra stuff since I got the same result already with the code you posted above.
Looking forward to see the fix in next release (hope so) and right after that you will get your answer marked as solution ;)
thanks (dzięki), Greg
Fix has been released in update 208 https://world.episerver.com/releases/episerver---update-208/
Thanks once again Bartosz!
Hi,
We need to store information about location into the property which is something like country + X cities. I thought it would be great to use for that PropertyList, so defined class for location like:
after that added to my page type property:
and also added class:
As an effect I got nice looking property for locations https://www.screencast.com/t/oGQhIrMitt
but the issue is when you click edit on single row the values from Cities list are lost https://www.screencast.com/t/9LIQcTr3WJN
Do I have something missing still to make it working? or is the PropertyList not designed to use collections in the class?
I assumed that do not need anymore to do serializer tricks which were needed in earlier Episerver (when it was Beta version) explained here https://world.episerver.com/blogs/Per-Magne-Skuseth/Dates/2015/11/trying-out-propertylistt/