Hi all,

I am writing a field component for a simple immutable value object which
is essentially the following:

    public class IntegerRange {
        private int minimum, maximum;

        public IntegerRange(int minimum, int maximum) {
            if (minimum > maximum)
                throw new IllegalArgumentException();
            this.minimum = minimum;
            this.maximum = maximum;
        }

        public int getMaximum() { return maximum; }
        public int getMinimum() { return minimum; }
    }

Now this value object is being used as part of a domain object so in the
form, I have:

    private class BulkEditForm extends Form {
        public BulkEditForm(String id) {
            super(id, new CompoundPropertyModel(new Template()));
            add(new IntegerRangeField("seats"));
        }
    }

I am using the TextField component for minimum and maximum fields so the
HTML of my IntegerRangeField panel looks like this:

<?xml version="1.0" encoding="utf-8"?>
<wicket:panel>
  <input wicket:id="min" type="text" class="text numeric" size="8" />
  &nbsp;-&nbsp;
  <input wicket:id="max" type="text" class="text numeric" size="8" />
</wicket:panel>

However, I don't know how to write a proper model for IntegerRangeField
component. I obviously cannot just do new Model(new IntegerRange(...))
because user input needs to be validated first and the immutable value
object doesn't allow invalid state. So, I probably need to store both,
minimum and maximum, in separate models for the two input fields. But
then I don't know how to update the 'seats' property in class Template!

I have tried overriding setObject() method for the two models for
updating the IntegerRange model, but then I need to add bunch of state
validation to ensure I don't feed invalid arguments to IntegerRange
constructor. Furthermore, I already have the validation in a
IFormValidator implementation so duplicating it doesn't seem to make too
much sense.

So how do I write a model for an immutable value object with state
validation?

Thanks,

                                Pekka



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to