Java tutorial
/* Copyright 2006 - 2010 Under Dusken Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package no.dusken.aranea.admin.control; import no.dusken.aranea.admin.editor.GenericEditor; import no.dusken.aranea.model.Section; import no.dusken.aranea.service.SectionService; import org.springframework.beans.factory.annotation.Required; import org.springframework.beans.propertyeditors.CustomBooleanEditor; import org.springframework.validation.Errors; import org.springframework.web.bind.ServletRequestDataBinder; import javax.servlet.http.HttpServletRequest; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; public class EditSectionController extends GenericEditController<Section> { private GenericEditor<Section> sectionEditor; private CustomBooleanEditor booleanEditor; public EditSectionController() { super(Section.class); } @Override protected Map referenceData(HttpServletRequest request, Object object, Errors errors) { Map<String, Object> map = new HashMap<String, Object>(); Set<Section> sections = new LinkedHashSet<Section>(); sections.add(null); SectionService sectionService = (SectionService) getGenericService(); sections.addAll(sectionService.getSections(false)); map.put("topLevelSections", sections); return map; } protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { super.initBinder(request, binder); binder.registerCustomEditor(Section.class, sectionEditor); binder.registerCustomEditor(Boolean.class, "active", booleanEditor); } @Required public void setSectionEditor(GenericEditor<Section> sectionEditor) { this.sectionEditor = sectionEditor; } @Required public void setBooleanEditor(CustomBooleanEditor booleanEditor) { this.booleanEditor = booleanEditor; } }