Ruslan Minasian
Nov 4, 2010
  3684
(0 votes)

Custom Property Type and SaveData Method

In out project we use PropertyPageReferenceCollection to store references to local pages. It has PageReferenceCollection under the hood and calls its Parse and ToString methods to load and save the data. Evetything was fine until we decided to make some property (let’s call it Links) of this type required. The application started to crash while loading the page with empty Links property.

I’ve spend a lot of time looking how to prevent LoadData from crash while the error was in SaveData method. When LocalPageProvider loads a page it goes through all the properties from DB calls PropertyData.LoadData method for each property which value is not DBNull.Value. Since our SaveData implementation used PageReferenceCollection.ToString it returned string.Empty for empty collection and that value was stored in the DB. Then, after we set Links property as required, LoadData started to crash since string.Empty caused PropertyData.Clear to be called for required property.

Moral: always implement SaveData property so it returns null if PropertyData.IsNull is true.

Nov 04, 2010

Comments

Please login to comment.
Latest blogs
Optimizely Forms: You cannot submit this form because an administrator has turned off data storage.

Do not let this error message scare you, the solution is quite simple!

Tomas Hensrud Gulla | Oct 4, 2024 | Syndicated blog

Add your own tools to the Optimizely CMS 12 admin menu

The menus in Optimizely CMS can be extended using a MenuProvider, and using the path parameter you decide what menu you want to add additional menu...

Tomas Hensrud Gulla | Oct 3, 2024 | Syndicated blog

Integrating Optimizely DAM with Your Website

This article is the second in a series about integrating Optimizely DAM with websites. It discusses how to install the necessary package and code t...

Andrew Markham | Sep 28, 2024 | Syndicated blog

Opticon 2024 - highlights

I went to Opticon in Stockholm and here are my brief highlights based on the demos, presentations and roadmaps  Optimizely CMS SaaS will start to...

Daniel Ovaska | Sep 27, 2024

Required fields support in Optimizely Graph

It's been possible to have "required" properties (value must be entered) in the CMS for a long time. The required metadata haven't been reflected i...

Jonas Bergqvist | Sep 25, 2024

How to write a bespoke notification management system

Websites can be the perfect vehicle for notifying customers of important information quickly, whether it’s the latest offer, an operational message...

Nicole Drath | Sep 25, 2024