KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > views > engines > helloworld > forms > HelloForm


1 package org.jahia.views.engines.helloworld.forms;
2
3 import javax.servlet.http.HttpServletRequest JavaDoc;
4
5 import org.apache.struts.action.ActionErrors;
6 import org.apache.struts.action.ActionForm;
7 import org.apache.struts.action.ActionMapping;
8 import org.apache.struts.action.ActionMessage;
9 import org.apache.struts.action.ActionMessages;
10
11 import org.jahia.exceptions.JahiaException;
12 import org.jahia.views.engines.*;
13 import org.jahia.views.engines.helloworld.actions.HelloAction;
14
15 /**
16  * Form bean for the hello page.
17  *
18  */

19 public final class HelloForm extends ActionForm {
20
21     public String JavaDoc getName() {
22         return (m_name);
23     }
24
25     public void setName(String JavaDoc name) {
26         m_name = name;
27     }
28
29     /**
30      * Reset all properties to their default values.
31      *
32      * @param mapping The mapping used to select this instance
33      * @param request The servlet request we are processing
34      */

35     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
36         m_name = null;
37     }
38
39     /**
40      * Validate the properties that have been set from this HTTP request,
41      * and return an <code>ActionErrors</code> object that encapsulates any
42      * validation errors that have been found. If no errors are found, return
43      * <code>null</code> or an <code>ActionErrors</code> object with no
44      * recorded error messages.
45      *
46      * @param mapping The mapping used to select this instance
47      * @param request The servlet request we are processing
48      */

49     public ActionErrors validate(ActionMapping mapping,
50                                  HttpServletRequest JavaDoc request) {
51         ActionErrors errors = new ActionErrors();
52
53         JahiaEngineCommonDataInterface jahiaEngineCommonData =
54             (JahiaEngineCommonDataInterface)request.getAttribute(JahiaEngineCommonData.JAHIA_ENGINE_COMMON_DATA);
55         try {
56             if (jahiaEngineCommonData == null) {
57                 jahiaEngineCommonData = new JahiaEngineCommonData(request);
58                 jahiaEngineCommonData.setEngineTitle(HelloAction.ENGINE_NAME);
59                 request.setAttribute(JahiaEngineCommonData.
60                                      JAHIA_ENGINE_COMMON_DATA,
61                                      jahiaEngineCommonData);
62             }
63         } catch ( JahiaException je ){
64             errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("error.engineCommonData.exception"));
65         }
66
67         if( m_name == null || m_name.length()==0 ){
68             errors.add("name",new ActionMessage("error.name.required"));
69         }
70         return (errors);
71     }
72
73
74
75     private String JavaDoc m_name = null;
76 }
77
78
Popular Tags