package org.example.TSA503.pages;
import org.apache.tapestry.annotations.*;
import org.apache.tapestry.corelib.components.*;
import org.example.TSA503.services.interfaces.UserAuthenticator;
/**
* Original code was taken from http://tapestry.apache.org/tapestry5/tapestry-core/guide/validation.html
* Modifications:
* - Added getters/setters for all variables
* - Commented UserAuthenticator injection and usage.
*/
public class Login
{
@Persist
private String _userName;
private String _password;
@Inject // was commented for Step 01.
private UserAuthenticator _authenticator; // was commented for Step 01.
@Component(id = "password")
private PasswordField _passwordField;
@Component
private Form _form;
String onSuccess()
{
if (!_authenticator.isValid(_userName, _password)) // was commented for Step 01.
{
_form.recordError(_passwordField, "Invalid user name or password.");
return null; //returns to the same page, i.e. "Login", something like "Try again".
}
return "Start"; //if authentication is valid, navigation will go to the "Start" page.
}
/**
* @return the _password
*/
public String getPassword()
{
return _password;
}
/**
* @param password to set
*/
public void setPassword(String password)
{
_password = password;
}
/**
* @return the _userName
*/
public String getUserName()
{
return _userName;
}
/**
* @param userName to set
*/
public void setUserName(String userName)
{
_userName = userName;
}
/**
* @return the _form
*/
public Form getForm() {
return _form;
}
/**
* @param _form the _form to set
*/
public void setForm(Form _form) {
this._form = _form;
}
/**
* @return the _passwordField
*/
public PasswordField getPasswordField() {
return _passwordField;
}
/**
* @param field the _passwordField to set
*/
public void setPasswordField(PasswordField field) {
_passwordField = field;
}
}
1 comment:
Very Good!
We really need T5 examples.
By the way, Login.java don't need getters and setters to _form.
Post a Comment