setCepToRemove(cepCourse.get(0));
}
Form form = new Form("form");
final ListChoice cepToAddList = new ListChoice("cepToAdd",
new PropertyModel(this, "cepToAdd"), cepDisponibles,
new CourseEnsemblePucesChoiceRenderer());
form.add(cepToAddList.setMaxRows(10).setNullValid(false).setEnabled(
course.isUtilisationPuces()));
final ListChoice cepToRemoveList = new ListChoice("cepToRemove",
new PropertyModel(this, "cepToRemove"), cepCourse,
new CourseEnsemblePucesChoiceRenderer());
form.add(cepToRemoveList.setMaxRows(10).setNullValid(false).setEnabled(
course.isUtilisationPuces()));
final Button addToCourseButton = new Button("addToCourse")
{
private static final long serialVersionUID = 1L;
@Override
public void onSubmit()
{
if (cepToAdd != null)
{
try
{
course.addCourseEnsemblePuce(cepToAdd);
courseService.save(course);
courseEnsemblePucesService.save(cepToAdd);
setResponsePage(new CoursePucesPage(course));
}
catch (ValidationException vex)
{
course.removeCourseEnsemblePuce(cepToAdd);
ValidationUtils.transferToComponent(vex, this);
}
}
}
};
form.add(addToCourseButton.setEnabled(course.isUtilisationPuces()));
final Button removeFromCourseButton = new Button("removeFromCourse")
{
private static final long serialVersionUID = 1L;
@Override
public void onSubmit()
{
if (cepToRemove != null)
{
course.removeCourseEnsemblePuce(cepToRemove);
courseService.save(course);
courseEnsemblePucesService.delete(cepToRemove);
setResponsePage(new CoursePucesPage(course));
}
}
};
form.add(removeFromCourseButton.setDefaultFormProcessing(false)
.setEnabled(course.isUtilisationPuces()));
form.add(new CoursePucesUpdatePanel("coursePucesUpdatePanel", course)
{
private static final long serialVersionUID = 1L;
@Override
protected void onUtilisationPucesChanged(boolean value)
{
cepToAddList.setEnabled(value);
cepToRemoveList.setEnabled(value);
addToCourseButton.setEnabled(value);
removeFromCourseButton.setEnabled(value);
}
});