loading table of contents...

Studio Developer Manual / Version 2310

Table Of Contents

9.21.3 Immediate Validation

Write requests that violate hard constraints of your content type model can be aborted when a validator fails. Typical use cases include:

  • Preventing a client from uploading an image that is too large.

  • Making sure that a content item does not link to itself directly.



Blocking writes is not normally useful for text properties, because text values are saved continuously as the user enters data, and a write interceptor might not be able to operate appropriately during the first saves. For blobs or link lists, the impact on the user experience is typically less of a problem. In any case, you need to make sure that the user experience is not impacted negatively.

For implementing immediate validation, you can create an instance of the class ValidatingContentWriteInterceptor as a Spring bean and populate its validators property with a list of PropertyValidator objects. When the validators are configured to report an error issue, an offending write will not be executed (that is, the requested value will not be saved).

A configuration that limits the size of images in the data property of CMPicture content items to 1 Mbyte might look like this (class names are wrapped for layout reasons):

  myValidatingContentWriteInterceptor(MaxBlobSizeValidator myMaxBlobSizeValidator) {

  ValidatingContentWriteInterceptor validatingContentWriteInterceptor =
    new ValidatingContentWriteInterceptor();
  return validatingContentWriteInterceptor;

MaxBlobSizeValidator myMaxBlobSizeValidator() {
  MaxBlobSizeValidator maxBlobSizeValidator =
    new MaxBlobSizeValidator();
  return maxBlobSizeValidator;

Example 9.98. Configuring Immediate Validation

Remember that the validators become active during creation, too, so that an immediate validator might validate initial values set by an earlier write interceptor.

Search Results

Table Of Contents

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.