JATO Tutorial
|
Let's create a page to display the data from our CustomersModel
__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
Customer.jsp
| Token | Replacement Text |
|---|---|
__appPackage__ |
jatotutorial |
__modulePackage__ |
module1 |
__page__ |
Customer |
<%@page info="Customer" language="java"%> |
__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
CustomerViewBean.jsp
| Token | Replacement Text |
|---|---|
__appPackage__ |
jatotutorial |
__modulePackage__ |
module1 |
__page__ |
Customer |
CHILD_CUSTOMERID,
CHILD_COMPANYNAME, CHILD_CONTACTNAME, CHILD_PHONE,
and CHILD_UPDATE. 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 registerChildren(), createChild(),
getWebActionModels(), getCustomersModel(), and handleUpdateRequest()
methods. Note, some parts of the template code have been omitted here. Any
omitted sections are not pertinent to this example:
package jatotutorial.module1;
...
public class CustomerViewBean extends ViewBeanBase
{
public CustomerViewBean()
{
super(PAGE_NAME);
setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
registerChildren();
}
protected void registerChildren()
{
registerChild(CHILD_CUSTOMERID,StaticTextField.class);
registerChild(CHILD_COMPANYNAME,TextField.class);
registerChild(CHILD_CONTACTNAME,TextField.class);
registerChild(CHILD_PHONE,TextField.class);
registerChild(CHILD_UPDATE,Button.class);
}
protected View createChild(String name)
{
if (name.equals(CHILD_CUSTOMERID))
{
StaticTextField child = new StaticTextField(this,
getCustomersModel(),
CustomersModel.FIELD_CUSTOMERID,
"");
return child;
}
else
if (name.equals(CHILD_COMPANYNAME))
{
TextField child = new TextField(this,
getCustomersModel(),
CustomersModel.FIELD_COMPANYNAME,
"");
return child;
}
else
if (name.equals(CHILD_CONTACTNAME))
{
TextField child = new TextField(this,
getCustomersModel(),
CustomersModel.FIELD_CONTACTNAME,
"");
return child;
}
if (name.equals(CHILD_PHONE))
{
TextField child = new TextField(this,
getCustomersModel(),
CustomersModel.FIELD_PHONE,
"");
return child;
}
else
if (name.equals(CHILD_UPDATE))
{
Button child = new Button(
this,
CHILD_UPDATE,
"Update");
return child;
}
else
{
throw new IllegalArgumentException(
"Invalid child name ["+name+"]");
}
}
public Model[] getWebActionModels(int executionType)
{
List modelList=new ArrayList();
switch (executionType)
{
case MODEL_TYPE_RETRIEVE:
modelList.add(getCustomersModel());
break;
case MODEL_TYPE_UPDATE:
modelList.add(getCustomersModel());
break;
case MODEL_TYPE_DELETE:
break;
case MODEL_TYPE_INSERT:
break;
case MODEL_TYPE_EXECUTE:
break;
}
return (Model[])modelList.toArray(new Model[modelList.size()]);
}
public CustomersModel getCustomersModel()
{
if (customersModel==null)
customersModel=(CustomersModel)getModel(CustomersModel.class);
return customersModel;
}
public void handleUpdateRequest(RequestInvocationEvent event)
throws ServletException, IOException
{
handleWebAction(WebActions.ACTION_UPDATE);
forwardTo();
}
public static final String PAGE_NAME="Customer";
public static final String DEFAULT_DISPLAY_URL=
"/jatotutorial/module1/Customer.jsp";
public static final String CHILD_CUSTOMERID="CustomerID";
public static final String CHILD_COMPANYNAME="CompanyName";
public static final String CHILD_CONTACTNAME="ContactName";
public static final String CHILD_PHONE="Phone";
public static final String CHILD_UPDATE="update";
private CustomersModel customersModel=null;
}
|
|
|