1 package org.jahia.views.engines.helloworld.actions; 2 3 import java.io.IOException ; 4 5 import javax.servlet.ServletException ; 6 import javax.servlet.http.HttpServletRequest ; 7 import javax.servlet.http.HttpServletResponse ; 8 9 10 import org.apache.struts.action.Action; 11 import org.apache.struts.action.ActionForm; 12 import org.apache.struts.action.ActionForward; 13 import org.apache.struts.action.ActionMapping; 14 import org.apache.struts.action.ActionMessage; 15 import org.apache.struts.action.ActionMessages; 16 import org.jahia.views.engines.*; 17 import org.jahia.exceptions.JahiaException; 18 import org.jahia.views.engines.helloworld.forms.HelloForm; 19 import org.jahia.bin.JahiaErrorDisplay; 20 21 24 public final class HelloAction extends Action { 25 26 public static final String ENGINE_NAME = "HelloWorld"; 27 28 43 public ActionForward execute(ActionMapping mapping, 44 ActionForm form, 45 HttpServletRequest request, 46 HttpServletResponse response) 47 throws IOException , ServletException { 48 49 ActionMessages errors = new ActionMessages(); 50 51 HelloForm helloForm = (HelloForm) form; 53 if ( helloForm == null ){ 54 return (new ActionForward(mapping.getInput())); 56 } 57 String name = helloForm.getName(); 58 59 request.setAttribute("helloForm",helloForm); 60 61 try { 62 64 JahiaEngineCommonData engineCommonData = 66 new JahiaEngineCommonData(request); 67 68 engineCommonData.setEngineTitle(ENGINE_NAME); 69 70 request.setAttribute(JahiaEngineCommonData.JAHIA_ENGINE_COMMON_DATA, 71 engineCommonData); 72 73 } catch ( JahiaException je){ 74 JahiaErrorDisplay.DisplayException(request, response, 75 super.getServlet().getServletContext(), je); 76 return null; 77 } 78 79 if (name == null || "".equals(name.trim())) { 82 errors.add("name",new ActionMessage("error.name.input")); 83 } 84 85 if (!errors.isEmpty()) { 88 saveErrors(request, errors); 89 return (new ActionForward(mapping.getInput())); 91 } 92 93 return (mapping.findForward("welcome")); 95 } 96 97 } 98 | Popular Tags |