Write requests that violate hard constraints of your document 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 document does not link to itself directly.
![]() | Caution |
|---|---|
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 documents to 1 Mbyte might look like this (class names are wrapped for
layout reasons):
<bean id="myValidatingInterceptor"
class="com.coremedia.rest.cap.intercept.
ValidatingContentWriteInterceptor">
<property name="type" value="CMPicture"/>
<property name="validators">
<list>
<bean class="com.coremedia.rest.cap.validators.
MaxBlobSizeValidator">
<property name="property" value="data"/>
<property name="maxSize" value="1000000"/>
</bean>
</list>
</property>
</bean>Example 7.66. 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.






![[Caution]](../common/images/caution.png)

