1 16 package com.blandware.atleap.webapp.action.testimonials; 17 18 import com.blandware.atleap.common.TestimonialModuleConstants; 19 import com.blandware.atleap.model.testimonials.Testimonial; 20 import com.blandware.atleap.service.testimonials.TestimonialManager; 21 import com.blandware.atleap.webapp.action.core.BaseAction; 22 import com.blandware.atleap.webapp.form.TestimonialForm; 23 import com.blandware.atleap.webapp.util.core.LocaleUtil; 24 import com.blandware.atleap.webapp.util.core.WebappConstants; 25 import com.blandware.atleap.webapp.util.testimonials.TestimonialModuleWebConstants; 26 import org.apache.struts.action.ActionForm; 27 import org.apache.struts.action.ActionForward; 28 import org.apache.struts.action.ActionMapping; 29 import org.apache.struts.action.ActionMessage; 30 import org.apache.struts.action.ActionMessages; 31 32 import javax.servlet.http.HttpServletRequest ; 33 import javax.servlet.http.HttpServletResponse ; 34 import java.util.List ; 35 36 56 public final class ViewTestimonialAction extends BaseAction { 57 66 public ActionForward execute(ActionMapping mapping, ActionForm form, 67 HttpServletRequest request, HttpServletResponse response) throws Exception { 68 TestimonialForm testimonialForm = (TestimonialForm) form; 69 Long testimonialId = null; 70 if ( testimonialForm.getId() != null ) { 71 testimonialId = Long.valueOf(testimonialForm.getId()); 72 } else if ( request.getSession().getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_ID_KEY) != null ) { 73 testimonialId = (Long ) request.getSession().getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_ID_KEY); 74 } else { 75 if ( log.isWarnEnabled() ) { 76 log.warn("Missing content page ID. Returning to list..."); 77 } 78 return mapping.findForward("listTestimonials"); 79 } 80 81 TestimonialManager testimonialManager = (TestimonialManager) getBean(TestimonialModuleConstants.TESTIMONIAL_MANAGER_BEAN); 82 Testimonial testimonial = testimonialManager.retrieveTestimonial(testimonialId); 83 if ( testimonial == null ) { 84 ActionMessages errors = new ActionMessages(); 86 errors.add("testimonialNotFound", new ActionMessage("testimonials.errors.notFound")); 87 saveErrors(request, errors); 88 return mapping.findForward("listTestimonials"); 89 } 90 91 List contentLocales = LocaleUtil.getInstance(servlet.getServletContext()).getAvailableLocales(); 92 93 request.getSession().setAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY, contentLocales); 94 95 request.setAttribute("testimonial", testimonial); 96 return mapping.findForward("viewTestimonial"); 97 } 98 } | Popular Tags |