IModel<Project> emptyProjectModel = new GenericEntityModel<Long, Project>(null);
Form<Project> projectForm = new StatelessForm<Project>("projectForm", emptyProjectModel);
noProjectContainer.add(projectForm);
// > > Project dropdown
final ProjectDropDownChoice projectDropDown = new ProjectDropDownChoice("project", emptyProjectModel);
projectDropDown.setRequired(true);
projectDropDown.setLabel(new ResourceModel("artifact.project.chooseOne"));
projectDropDown.add(new LabelPlaceholderBehavior());
projectForm.add(projectDropDown);
// > > Project form AJAX submit link
projectForm.add(new AjaxSubmitLink("addToProject", projectForm) {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
Artifact artifact = ArtifactProjectPanel.this.getModelObject();
Project selectedProject = projectDropDown.getModelObject();
if (selectedProject != null) {
if (artifact.getProject() == null) {
try {
projectService.addArtifact(selectedProject, artifact);
getSession().success(getString("artifact.project.add.success"));
} catch (Exception e) {
LOGGER.error("Unknown error occured while adding an artifact to a project", e);
getSession().error(getString("artifact.project.add.error"));
}
} else {
LOGGER.error("Artifact already added to a project");
getSession().warn(getString("artifact.project.add.alreadyHasProject"));
}
}
projectDropDown.setModelObject(null);
target.add(getPage());
FeedbackUtils.refreshFeedback(target, getPage());
}
@Override