AnsweredAssumed Answered

How to create a custom Constraint on a d:date Property

Question asked by ipirat on May 26, 2014
Latest reply on May 26, 2014 by ipirat
Hi all,

I have a custom model with two custom properties of type d:date (my:fromDate and my:toDate), both are mandatory
Now I'd like to ensure that that the my:toDate is equal or later than the my:fromDate.

<li>My first goal is to implement a custom Constraint class, which takes two (constant) constraint properties: minDate and maxDate
<li>My second goal is to implement a custom Constraint class, which compares to content properties.

<strong>To achieve my first goal,</strong> I created a class my.package.constraints.DateMinMaxConstraint (see code below) and defined my content model:

                <property name="my:fromDate">
                    <title>From Date</title>
                    <mandatory enforced="true">true</mandatory>
                        <constraint name="my:minMaxDateConstraint" type="my.package.constraints.DateMinMaxConstraint">
                            <parameter name="minDate">
                            <parameter name="maxDate">

Now, that complaints along the lines of

llegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'minDate': no matching editors or conversion strategy found

apparently, I need to give it a PropertyEditor. => First Question: How can I specify a PropertyEditor to be used with a constraint??? Do I need to edit one of the spring xml files?

public class DateMinMaxConstraint extends AbstractConstraint {

    private Date minDate;
    private Date maxDate;

    public Date getMinDate() {
        return this.minDate;

    public void setMinDate(Date minDate) {
        this.minDate = minDate;

    public Date getMaxDate() {
        return this.maxDate;

    public void setMaxDate(Date maxDate) {
        this.maxDate = maxDate;

    public Map<String, Object> getParameters() {
        Map<String, Object> params = new HashMap<String, Object>(2);
        params.put("minDate", this.minDate);
        params.put("maxDate", this.maxDate);
        return params;

    protected void evaluateSingleValue(Object val) {
        // TODO this is just to be able to set a break point for the moment
        int i = 0;



For my second goal: I have no idea, to be honest: is it possible at all, to compare two document properties in one constraint