November Happy Hour will be moved to Thursday December 5th.

CollectionEditorDescriptor does not show value of calculated field in table after adding new record

Vote:
 

In my project, we have a field using IList<Item> in a page type, we have an issue when we edit a page using this page type:

When I add a new value to IList using CollectionEditorDescriptor:

The value of Label is not showed after clicking Add button:

But after refreshing this page, the value of Label is shown again.

My implemtation for this field is:

Page type: StartPage.cs

[ContentType(
    GUID = "19671657-B684-4D95-A61F-8DD4FE60D559",
    GroupName = Global.GroupNames.Specialized)]
public class StartPage : PageData
{
    [Display(
	GroupName = SystemTabNames.Content,
	Order = 320)]
    [CultureSpecific]
    public virtual ContentArea MainContentArea { get; set; }

    [Display(
	GroupName = SystemTabNames.Content,
	Order = 321)]
    [CultureSpecific]
    [BackingType(typeof(PropertyItem))]
    public virtual IList<Item> Items { get; set; }
}

Item.cs:

public class Item
{
	public virtual string Text { get; set; }

	public virtual string Label
	{
		get
		{
			return "Label of " + Text;
		}
	}
}

PropertyItem.cs:

[PropertyDefinitionTypePlugIn]
public class PropertyItem : PropertyList<Item>
{
	protected override Item ParseItem(string value)
	{
		return JsonConvert.DeserializeObject<Item>(value);
	}
}

ItemEditorDescriptor.cs:

[EditorDescriptorRegistration(TargetType = typeof(IList<Item>))]
public class ItemEditorDescriptor : CollectionEditorDescriptor<Item>
{
	public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
	{
		base.ModifyMetadata(metadata, attributes);
	}
}

Notice: This issue happend after upgrading to Episerver CMS 11. In Episerver CMS 10, no issue.

#204101
May 20, 2019 6:15
Vote:
 

If i remember properly you could set the IList property to specified as a JsonProperty via the library Newtonsoft, something like this:

[Display(
   GroupName = SystemTabNames.Content,
   Order = 321)]
[CultureSpecific]
[JsonProperty]
[JsonConverter(typeof(UrlConverter))]
[BackingType(typeof(PropertyItem))]
public virtual IList<Item> Items { get; set; }

This should most likely help the convert the properly and read it properly for the Episerver CMS

#204102
May 20, 2019 6:23
Vote:
 

@Eric: I tried your solution, but the value of Label field still is not showed

#204103
May 20, 2019 6:50
Vote:
 

Do you get any specific console error in the web console window?

Any errors in Episerver's logs?

#204104
May 20, 2019 6:52
Vote:
 

@Eric: Thers is no error in the web console window and Episerver's logs.

#204105
May 20, 2019 6:59
Vote:
 

Have you decorated your Items property with the CollectionEditorDescriptor?

[EditorDescriptor(EditorDescriptorType = 
   typeof(CollectionEditorDescriptor<Item>))]
public virtual IList<Item> Items { get; set; }
#204106
May 20, 2019 7:30
Vote:
 

 @Eric: I decorated my Items property with the CollectionEditorDescriptor in ItemEditorDescriptor.cs:

[EditorDescriptorRegistration(TargetType = typeof(IList<Item>))]
public class ItemEditorDescriptor : CollectionEditorDescriptor<Item>
{
	public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
	{
		base.ModifyMetadata(metadata, attributes);
	}
}
#204107
May 20, 2019 7:34
Vote:
 

@LeMingDuc: I recently came across another client whom I was suppose to implement the same kind of solution that I had got working for another client.

Turns out I got an error for naming conventions on the properties for the IList type reference property called Name

I had named my property class to ControlSystem and with a property declared as:

public string Name { get; set; }

This got in conflict with another property declared Name on that page in Episerver.

I see that you named your property to Item - perhaps this get's in conflict aswell in later usages of Episerver?

Or your only property in conflict, the Label property?

#204811
Edited, Jun 19, 2019 0:37
Vote:
 

I'm also encountering this issue, also only for a calculated field.

Did you manage to resolve this issue by any chance?

I've tried overriding the default CollectionEditorDescriptor js editor, and can see that the calculated field never makes it to the front-end.

#205539
Edited, Jul 16, 2019 9:36
Vote:
 

Any updates on this issiue?

I'm facing the same problem (computed value isn't shown unless I refresh the editor's UI) and my code is very similar to code posted by original poster. We're using version 11.17.0

I'd be really grateful for any info.

#229157
Edited, Oct 08, 2020 9:47
Vote:
 

For any late comers to this thread (like me)... it seems this was fixed in version 11.36.0 with a new attribute from EPiServer.Cms.Shell.UI.ObjectEditing namespace called ReloadOnChangeAttribute.

    [Display(
	GroupName = SystemTabNames.Content,
	Order = 321)]
    [CultureSpecific]
    [BackingType(typeof(PropertyItem))]
    [ReloadOnChange]
    public virtual IList<Item> Items { get; set; }
#275306
Mar 02, 2022 5:26
* 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.