Hi Stefan,
Malcolm Edgar wrote:
I would recommend using the PickList control, its excelent for this
kind of thing. It doesn't have native Cayenne support however so you
need to write a little code.
Just to expand on this a bit, CayenneForm (or rather the underlying
Form) doesn't support copying of to-many relationships since there
isn't enough data available for it to know which type of relationship
to create.
So what Malcolm means by writing code is you need to manage the
relationship yourself.
In your Page you would normally have a place where you load the data
and store the data. These are ideal places to manage the relationship e.g:
public class MyPage extends Page {
private QuerySelect selectedCourses;
...
/** Load the student object to edit. */
public void onEditClick() {
Integer id = editLink.getValueInteger();
if (id != null) {
// Load a student to edit
Student student = (Student) getDataObject(id);
// Student can have many courses
List courses = client.getCourses();
// Setup the QuerySelect selectedValues
List selectedValues = new ArrayList();
for (int i = 0; i < courses.size(); i++) {
Course course = (Course) student.get(i);
selectedValues.add(course.getId());
}
selectedCourses.setSelectedValues(selected);
}
}
/** Store the new student info */
public void onSaveClick() {
if (form.isValid()) {
Student student = (Student) form.getDataObject();
List selectedValues = selectedClients.getSelectedValues();
// With the selected courses in hand you need to update
// the Student object.
...
saveDataObject(student);
}
}
}
kind regards
bob
regards Malcolm Edgar
On Sun, Apr 12, 2009 at 1:02 AM, Stefan Klein <[email protected]> wrote:
Hello,
i'm building my first a small web application with click & cayenne, it's
basicly a relativ simple database frontend.
On one page i'd like to use a multiselect or a field of checkboxes (not so sure yet) to
represent a many to many relation. In Cayenne I defined a "flattened
relationship" as described at
http://cayenne.apache.org/doc20/flattened-relationships.html.
I tried PropertySelect from the extras.cayenne package but it doesn't support
Multiselect. With QuerySelect I get the multiselection field rendered but i
don't know how to save the selected values.
Did i miss something in the documentation, is there any example of using
multiselect with cayenne?
If i decide to use a field of checkboxes for this, best aproach would be to
implement an own class which handles the complete field of checkboxes like the
select class handles the selection field, right?
thanks & regards,
Stefan Klein
--
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen:
http://www.gmx.net/de/go/multimessenger01