/* 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.model.Article; import no.dusken.aranea.model.FactBox; import no.dusken.aranea.service.ArticleService; import org.springframework.beans.factory.annotation.Required; import org.springframework.validation.BindException; import org.springframework.validation.Errors; import org.springframework.web.bind.ServletRequestUtils; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.Map; /** * @author Marvin B. Lillehaug <lillehau@underdusken.no> * Edits a factbox */ public class EditFactBoxController extends GenericEditController<FactBox> { private ArticleService articleService; public EditFactBoxController() { super(FactBox.class); } @Override protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object o, BindException e) throws Exception { FactBox factBox = (FactBox) o; //adding the article Long articleID = ServletRequestUtils.getLongParameter(request, "articleID", 0); Article article = articleService.getEntity(articleID); factBox.setArticle(article); return super.onSubmit(request, response, factBox, e); } @Override protected Map referenceData(HttpServletRequest request, Object object, Errors errors) throws Exception { Map<String, Object> map = super.referenceData(request, object, errors); //adding id to map, so we can add a return to article link even when the article isnt saved. Long articleID = ServletRequestUtils.getLongParameter(request, "articleID", 0); map.put("articleID", articleID); return map; } @Required public void setArticleService(ArticleService articleService) { this.articleService = articleService; } }