packtpub.celebrities.model.User;
import org.apache.tapestry.annotations.ApplicationState;
import org.apache.tapestry.annotations.OnEvent;
public class Start
{
private String userName;
private String password;
@ApplicationState
private User user;
Object onSubmitFromLoginForm()
{
Class nextPage = null;
User authenticatedUser = null;
authenticatedUser =
Security.authenticate(userName, password);
if (authenticatedUser != null)
{
user = authenticatedUser;
nextPage = ShowAll.class;
}
else
{
nextPage = Registration.class;
}
return nextPage;
}
public String getUserName()
{
return userName;
}
public void setUserName(String userName)
{
this.userName = userName;
???
Chapter 4
[ 93 ]
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
}
First of all, please note that the event handler, onSubmitFromLoginForm method
was named appropriately in order to handle the submit event of the loginForm
component. It returns an object, in this case a class. As the previous chapter
explained, this is a preferred, type-safe way of telling Tapestry which page we want
it to show next. If validation was successful, the class for the ShowAll page will be
returned; otherwise the returned class will be for the Registration page.
Pages:
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130