[email protected] wrote:
thanks for the explanation and the example code.
Got it working, but i get an ognl.NoSuchPropertyException when
form.saveChanges() is called.
I guess it's because, like you described, CayenneForm doesn't know about the
to-many relation and is trying to access the normal setter for
QuerySelect->name when the form is saved.
Is it save to ignore this Exeption or should/can i tell CayenneForm to ignore
this particular field?
You *could* ignore it as the other properties are still copied, but
you *should not* as your log will be filled with stack traces.
Form.copyTo and copyFrom maps fields to object properties based on
their names. So you could either:
1 - rename the Field to not match the property e.g:
QuerySelect("courseList") instead of QuerySelect("courses")
2 - override the Form.copyTo and copyFrom and exclude fields that
should not be copied:
public class MyPage extends BorderPage {
private QuerySelect selectedCourses = new QuerySelect("courses");
public MyPage() {
CayenneForm form = new CayenneForm("form") {
public void copyTo(Object object) {
// Retrieve all fields for the Form and remove QuerySelect
List fieldList = ContainerUtils.getInputFields(this);
fieldList.remove(selectedCourses);
ContainerUtils.copyContainerToObject(this, object, fieldList);
}
public void copyFrom(Object object) {
// Retrieve all fields for the Form and remove QuerySelect
List fieldList = ContainerUtils.getInputFields(this);
fieldList.remove(selectedCourses);
ContainerUtils.copyObjectToContainer(object, this, fieldList);
}
}
...
}
}
As you can see from #2 above, Form's copyTo and copyFrom methods
delegates to ContainerUtils copying, so one can override these methods
and manipulate the Fields before copying.
Hope this helps.
kind regards
bob