JATO Tutorial
|
Let's create the first page of our application.
__page__.jsp
from the /templates/1_2/ModuleTemplates
directory to your /jatotutorial/module1
directory. Please
note that we are now working with the documents directory, not the Java
packages directory in the /WEB-INF/classes
directory
/JatoTutorial/jatotutorial/module1/__page__.jsp
Login.jsp
Token | Replacement Text |
---|---|
__appPackage__ |
jatotutorial |
__modulePackage__ |
module1 |
__page__ |
Login |
<%@page info="Login" language="java"%> <%@taglib uri="/WEB-INF/jato.tld" prefix="jato"%> <jato:useViewBean className="jatotutorial.module1.LoginViewBean"> ... <html> <head> <title>Login</title> </head> <body> <jato:form name="Login"> <h1><jato:text name="statusMessage" escape="true"/></h1> <p> Login:<jato:textField name="login" size="20" maxLength="20"/> <p> Password:<jato:password name="password" size="20" maxLength="20"/> <p> <jato:button name="submit"/> </jato:form> </body> </html> </jato:useViewBean> |
__page__ViewBean.java
from the /templates/1_2/ModuleTemplates
directory to your /WEB-INF/classes/jatotutorial/module1
directory./JatoTutorial/WEB-INF/classes/jatotutorial/module1/__page__ViewBean.java
LoginViewBean.java
Token | Replacement Text |
---|---|
__appPackage__ |
jatotutorial |
__modulePackage__ |
module1 |
__page__ |
Login |
CHILD_UID
,
CHILD_PWD
, CHILD_SUBMIT
, and CHILD_MESSAGE
.
(Note that the values for these name constants must correspond exactly
with the field names in the JSP we just created.) Also add the code for
the createChild()
, registerChildren()
, and handleSubmitRequest()
methods. Note, some parts of the template code have been omitted here.
Any omitted sections are not pertinent to this example.
package jatotutorial.module1; import java.io.*; import java.lang.reflect.*; import java.sql.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import jatotutorial.*; import com.iplanet.jato.*; import com.iplanet.jato.model.*; import com.iplanet.jato.model.sql.*; import com.iplanet.jato.util.*; import com.iplanet.jato.view.*; import com.iplanet.jato.view.event.*; import com.iplanet.jato.view.html.*; public class LoginViewBean extends ViewBeanBase { public LoginViewBean() { super(PAGE_NAME); setDefaultDisplayURL(DEFAULT_DISPLAY_URL); registerChildren(); } protected void registerChildren() { registerChild(CHILD_MESSAGE,StaticTextField.class); registerChild(CHILD_LOGIN,TextField.class); registerChild(CHILD_PASSWORD,TextField.class); registerChild(CHILD_SUBMIT,Button.class); } protected View createChild(String name) { if (name.equals(CHILD_MESSAGE)) { StaticTextField child = new StaticTextField(this, CHILD_MESSAGE, ""); return child; } else if (name.equals(CHILD_LOGIN)) { TextField child = new TextField(this, CHILD_LOGIN, ""); return child; } else if (name.equals(CHILD_PASSWORD)) { TextField child = new TextField(this, CHILD_PASSWORD, ""); return child; } else if (name.equals(CHILD_SUBMIT)) { Button child = new Button(this, CHILD_SUBMIT, "Submit"); return child; } else throw new IllegalArgumentException( "Invalid child name \""+name+"\""); } ... public void handleSubmitRequest(RequestInvocationEvent event) throws ServletException, IOException { // Retrieve the login name & password String loginName = getDisplayFieldStringValue(CHILD_LOGIN); String password = getDisplayFieldStringValue(CHILD_PASSWORD); String theMessage = ""; // Check the login name // Note, we don't check the password in this example if (loginName.equalsIgnoreCase("anton") || loginName.equalsIgnoreCase("alfki") || loginName.equalsIgnoreCase("bonap")) { theMessage = "Congratulations, " + loginName + ", you are now logged in!"; } else { theMessage = "Sorry, " + loginName + ", your login or passsword was incorrect!"; } // Set the ouput status message getDisplayField(CHILD_MESSAGE).setValue(theMessage); // Redisplay the current page forwardTo(); } ... // The "logical" name for this page public static final String PAGE_NAME="Login"; // The URL that points to the JSP which uses this ViewBean public static final String DEFAULT_DISPLAY_URL= "/jatotutorial/module1/Login.jsp"; public static final String CHILD_MESSAGE = "statusMessage"; public static final String CHILD_LOGIN = "login"; public static final String CHILD_PASSWORD = "password"; public static final String CHILD_SUBMIT = "submit"; } |
|