Things need to be asked before the development process

We all know that web development is often driven by concepts and marketing. The goals are msotly marketing related, so as a technical fellow, you’re not leading. As professional developer you should know that such a view has a positive and negative side: positive because it’s driven by goals, not just ‘where they ask for’, negative because technical solutions are always on the budget side of the project. So you’ve to work efficient. Working efficient means most of the time that you’ll skip some parts. To prevent you from making mistakes while designing the solution, I want to make you aware of the following questions which should be asked:

  1. Do you know where to host your solutions and on which infrastructure?
  2. We can design Sitecore in 2 ways: single site, multisite…. Single site means that it’s used for 1 site, changing it later on is hardly impossible and very time intensive. Multisite costs way more at the first stage but prepares your solution for more sites.
  3. How many users will use Sitecore? Do they have different roles? For different Sites?
  4. What’s the primairy way of using Sitecore? Should be optimize the website for web-editing? Or will you only use the Content Editor?
  5. What’s more important? Lower costs on Sitecore design or more system usability(means more efficient content editing => more productivity for content editors)?
  6. What’s the more important, that the (X)HTML is valid and readable for software or that the site has rich interaction such as AJAX technologies.

This list is at the moment way to short and should expanded, but this is allI can think of by now.

I’m off for some days to Val Thorens. Snowboarding(for what’s left of the snow) and partying a lot. I’m back around the 7th of may.

Where and how to check your data?

Since 3 weeks we’ve got a new colleague at work: Rob. Rob is a very skilled (ASP).NET (senior) developer and we’re introducing him to the world of Content Management. So far he hasn’t worked with a predefined system as Sitecore is. And everytime someone like Rob joins your team, you’ll have new exciting discussion about implementations.

One of the discussion I’ve had was all about data integrity. Where do you want to check that a user just has selected 6 items for displaying? And not, as they often do, select 8, contact our support-team why the last 2 items aren’t displayed.

In Robs opinion, you should check it on 1 sides: CMS and not on the front-end. And while writing this entry, I’m still 100% not sure wether he’s right or not. Let me explain you why:

First of all, for the visitor, only 6 links should be showed. You’ve to make sure you don’t allow more, but for far can you go with trusting your content editors? Should you actually limit them? Is that recommended? Wouldn’t such a ‘hook’ be the end of the flexibility in the system? Is such logic allowed in your data-tier? Or in your presentation logic?

In any case:

  • I don’t want more items then allowed to be stored in my database
  • I don’t want to write extremely inflexible(and ofcourse also flexible) ‘codes’ like regex’s which are interpretated  on runtime instead of compile time
  • I don’t want any logic in my front-end on limiting data
  • I definitely don’t want to confuse the CMS user

The requirements implicate that the validation can’t be done at the final (presentation) tier. The user shouldn’t be set on the wrong path, so the data he saves shouldn’t be presented on their front-end on another way as it’s represented in the CMS-client. But the default Sitecore validation does not match the requirements. Why not? Well it’s executed at runtime, so for example I’m never able to check if all IDs exists within Sitecore. Or if the match may be made(folders-items together with data-items, etc).

Therefor I’m definitelly happy with the new functionality within Sitecore 5.3.1 :). As the validation can be done direct in Sitecore, it’s validated on runtime, but not intrepreted on runtime(which is actually the requirement).

But, what to do when your logic is incorrect? And side-effects? Such an incomplete indexes? In those cases you want to be sure that your website is displayed correct. Shouldn’t you create a ‘failback’ in your presentation code? Therefor, I’m still a bit doubting…

Hooking into the Core: Pipelines and Validation in 5.3.1

The days around Easter are always wonderfull to make up your mind, get over the busy start of the year and become prepared for a just another shiny summer :). And to start blogging again as I’ve been very busy without having the change to share my thoughts. Peter already did an excellent job on describing what is changed in the last build of Sitecore. Ofcourse, I wouldn’t be myself trying to beat Peter with a pretty in-depth article on hooking in the core making advantage on some new functionality… As I speak Peter nearly on daily base on Messenger, I’m sure he won’t mind. Actually, I expect him to ‘beat’ me again later this week!

Back to Sitecore: This saturday I’ve placed a fresh 5.3.1 installation on my laptop and after a short time of running trough apps like the Content Editor, my eyes were caught by the following settings:

Some validation settings for fields and items? Hmm, interesting! So I opened the Template manager and found out that the Base Template has new field: ‘Rules’ which is a treelist  with the datasource to the validation-settings-folder. The Template field has a new field called ‘Validation rules’:

Also: Check out the ‘Base Template’ button, which is added on(not only) mine request, so base templates are easier definable.

Back to validation: let’s take a closer look at a validator. In this case the Max Length 40:

What we see is a reference to a class in the Sitecore.Kernel and the possibility to pass a parameter to this class. By now, you proparly already opened your Reflector and are looking at the namespace Sitecore.Data.Validators:

As you can see, there’s a Manager, Message, MessageType, Result and a Rule. The manager is used to apply the rules on the items and get back the results filled with messages. The other classes in the namespace are implementation based on ValidatonRule.

So I though, wow cooool! We finally get the possibility to define our own rules… But after some test I’ve found out the rules weren’t really called by the client? It seems not to be called? Or it might be used for the Media Library, but not in the way I expect it should work! It should prevent the user from saving this item…
But still, why is it so obvious available in the templates, but can’t we find the functionality? Is this an undocumented feature which will be documented in 5.4? Do I just miss the pipeline processor? Seems so! After some investigation, I’ve decided to write one, below you can find the result. Make sure you install it on the last bits of Sitecore and use it at your own risk. Akthough it should be tested pretty well:

    1 using Sitecore.Data.Items;

    2 using Sitecore.Data.Validators;

    3 using Sitecore.Pipelines.Save;


    5 namespace Sitecore.Pipelines.Save.Validation

    6 {

    7     /// <summary>

    8     /// Executes intensive validation rules on an item.

    9     /// </summary>

   10     public class ValidationRuleProcessor

   11     {

   12         public void Process(SaveArgs args)

   13         {

   14             //Walk trough the items in the pipeline arguments

   15             foreach (SaveArgs.SaveItem saveItem in args.Items)

   16             {

   17                 //Retrieve the last saved version of the item

   18                 Item orgItem = Context.ContentDatabase.Items[saveItem.ID, saveItem.Language, saveItem.Version];


   20                 //Start editing the item and overwrite the field with the saved ones

   21                 orgItem.Editing.BeginEdit();

   22                 foreach (SaveArgs.SaveField field in saveItem.Fields)

   23                 {

   24                     orgItem.Fields[field.ID].Value = field.Value;

   25                 }


   27                 //Create a result object and validate the item

   28                 ValidationResult valResult = new ValidationResult();

   29                 ValidationManager.Validate(valResult, orgItem);


   31                 //Walk trough the messages and displey them

   32                 //When a Error occurs, abort the pipeline so the item isn’t saved

   33                 foreach (ValidationMessage message in valResult.Messages)

   34                 {

   35                     Context.ClientPage.ClientResponse.Alert(message.Message);


   37                     if (message.Type == ValidationMessageType.Error)

   38                     {

   39                         args.Abort();

   40                         return;

   41                     }

   42                 }


   44                 //Reject the changes, savind will be done in a later stage of the pipeline

   45                 orgItem.Editing.RejectChanges();

   46             }

   47         }

   48     }

   49 }

Add it to the saveUi pipeline just behind the regular validation step(Sitecore.Pipelines.Save.ValidateFields, Sitecore.Kernel). And enjoy advanced validation on both Items and Fields!
Next posts, I’ll discuss the advanced possibilities you get from this kind of validation. Later on, I’ll publish some of the events, pipeline-components, etc, I’ve written lasts month(-s).