I'm following this MVC model: http://java.sun.com/developer/technicalArticles/javase/mvc/
In my model I have an "ArrayList shapes" field and I need the shapes in my view.
Is the only way of getting my shapes by getting them in the modelPropertyChange method?
public void modelPropertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(MyController.PROPERTY_TEXT)) {
ArrayList<Shape> shapes = (ArrayList<Shape>) evt.getNewValue();
}
}
or should I also create a generic getter method in my controller? like this generic setter method:
protected void setModelProperty(String propertyName, Object newValue) {
for (AbstractModel model: registeredModels) {
try {
Method method = model.getClass().
getMethod("set"+propertyName, new Class[] {
newValue.getClass()
}
);
method.invoke(model, newValue);
} catch (Exception ex) {
// Handle exception.
}
}
}
If I need such a generic getter method, I have no clue how to transform this generic setter above to a generic getter method. If I don't need such a generic getter method to retreive my data from the model, if I only need the modelPropertyChange method from my View. How would I get my data from the model the first time the application starts? :o
Pfft I need to get my arraylist of shapes from my model in my view :( (and later I need to get some other data also) So confusing :(