Main changes are in green colour:
package org.example.TSA504.pages;
import org.apache.tapestry.annotations.ApplicationState;
import org.apache.tapestry.annotations.Inject;
import org.example.TSA504.beans.TUser;
import org.example.TSA504.services.interfaces.UserAuthenticator;
/* BeanEditForm usage example from the ScreenCast#4 - http://tapestry.apache.org/tapestry5/screencast.html
* To get more details - http://elozovan.blogspot.com
* */
public class UpdateExisting {
@ApplicationState
private TUser _tUser; //TUser bean.
private String _tUserName;
@Inject
private UserAuthenticator _authenticator;
/* @Component //for future...
private BeanEditForm _form;*/
String onSuccess() {
if (_tUser==null){ return null;}
if (!(_authenticator.addNewTUser(_tUser))){
//_form.recordError("Sorry, a error has occured upon adding the user"); // For some reason BeanEditForm
hasn't recordError() (inspite of JavaDoc).
return null;
}
_tUser = null;
return "Start";
}
/*See for theory: http://tapestry.apache.org/tapestry5/tapestry-core/guide/pagenav.html
*onActivate()+ onPassivate() are used for getting TUser fields values upon selecting on the Home page. */
void onActivate(String userName)
{
_tUserName = userName;
_tUser = _authenticator.getTUserByUserName(_tUserName);
}
String onPassivate() { return _tUserName; }
/**
* @return the (TUser)_tUser object.
*/
public TUser getTUser() {
return _tUser;
}
}
Showing posts with label tapestry 5. Show all posts
Showing posts with label tapestry 5. Show all posts
21 July 2007
Home.html, Step XY - BeanEditForm and Grid
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<head>
<title>Home</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<style type="text/css">
#spisok {
position: absolute;
left: 40%;
top: 30%;
margin-right: auto;
margin-left: auto;
}
</style>
<body>
[<a t:type="PageLink" page="Start">Start</a>]
<br/>
[<a t:type="PageLink" page="AddNew">Add New/a>]
<br/>
[<a t:type="PageLink" page="Registration">Registration</a>]
<div id="spisok" title="Рыба" align = "justify">
<table t:type="grid" rowsPerPage="5" source="usersList">
<t:parameter name="passwordCell">
*****
</t:parameter>
</table>
</div>
</body>
</html>
<head>
<title>Home</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<style type="text/css">
#spisok {
position: absolute;
left: 40%;
top: 30%;
margin-right: auto;
margin-left: auto;
}
</style>
<body>
[<a t:type="PageLink" page="Start">Start</a>]
<br/>
[<a t:type="PageLink" page="AddNew">Add New/a>]
<br/>
[<a t:type="PageLink" page="Registration">Registration</a>]
<div id="spisok" title="Рыба" align = "justify">
<table t:type="grid" rowsPerPage="5" source="usersList">
<t:parameter name="passwordCell">
*****
</t:parameter>
</table>
</div>
</body>
</html>
TSA504.pages.Registration, Step XY - BeanEditForm and Grid
package org.example.TSA504.pages;
import org.apache.tapestry.annotations.ApplicationState;
import org.apache.tapestry.annotations.Inject;
import org.example.TSA504.beans.TUser;
import org.example.TSA504.services.interfaces.UserAuthenticator;
/* BeanEditForm usage example from the ScreenCast#4 - http://tapestry.apache.org/tapestry5/screencast.html*/
public class Registration {
@ApplicationState
private TUser _addnew;
@Inject
private UserAuthenticator _authenticator;
/* @Component //for future...
private BeanEditForm _form;*/
String onSuccess() {
if (_addnew==null){ return null;}
if (!(_authenticator.addNewTUser(_addnew))){
//_form.recordError("Sorry, a error has occured upon adding the user"); // For some reason BeanEditForm hasn't recordError() (inspite of JavaDoc).
return null;
}
_addnew = null; //Destroying user data from "session"
return "Start";
}
/**
* @return the _addnewPage
*/
public TUser getAddnew() {
return _addnew;
}
}
import org.apache.tapestry.annotations.ApplicationState;
import org.apache.tapestry.annotations.Inject;
import org.example.TSA504.beans.TUser;
import org.example.TSA504.services.interfaces.UserAuthenticator;
/* BeanEditForm usage example from the ScreenCast#4 - http://tapestry.apache.org/tapestry5/screencast.html*/
public class Registration {
@ApplicationState
private TUser _addnew;
@Inject
private UserAuthenticator _authenticator;
/* @Component //for future...
private BeanEditForm _form;*/
String onSuccess() {
if (_addnew==null){ return null;}
if (!(_authenticator.addNewTUser(_addnew))){
//_form.recordError("Sorry, a error has occured upon adding the user"); // For some reason BeanEditForm hasn't recordError() (inspite of JavaDoc).
return null;
}
_addnew = null; //Destroying user data from "session"
return "Start";
}
/**
* @return the _addnewPage
*/
public TUser getAddnew() {
return _addnew;
}
}
Registration.html, Step XY - BeanEditForm and Grid
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<head>
<title>Registration</title>
</head>
<body>
<h1>Enter your registration information below</h1>
<form t:type="BeanEditForm" object="addnew" submitLabel="Create"/>
[<a t:type="PageLink" page="Start">Start</a>]
<br/>
[<a type="PageLink" page="Login">Login</a>]
</body>
</html>
<head>
<title>Registration</title>
</head>
<body>
<h1>Enter your registration information below</h1>
<form t:type="BeanEditForm" object="addnew" submitLabel="Create"/>
[<a t:type="PageLink" page="Start">Start</a>]
<br/>
[<a type="PageLink" page="Login">Login</a>]
</body>
</html>
11 June 2007
TSA504.pages.Home -Step 06
Refers to ...
Only last modifications are shown:
public class Home {
@Inject
private BeanModelSource _beanModelSource;
@Inject
private ComponentResources _resources;
@Retain
private BeanModel _model;
...
//Inspired by http://tapestry.apache.org/tapestry5/tapestry-core/guide/beaneditform.html
void pageLoaded()
{
_model = _beanModelSource.create(TUser.class, true, _resources);
_model.remove("password"); //Just for "password" column not to be displayed on the Home page, in the grid. But is's displayed on BeanEditFromPage (UpdateExisting).
}
...
}
Only last modifications are shown:
public class Home {
@Inject
private BeanModelSource _beanModelSource;
@Inject
private ComponentResources _resources;
@Retain
private BeanModel _model;
...
//Inspired by http://tapestry.apache.org/tapestry5/tapestry-core/guide/beaneditform.html
void pageLoaded()
{
_model = _beanModelSource.create(TUser.class, true, _resources);
_model.remove("password"); //Just for "password" column not to be displayed on the Home page, in the grid. But is's displayed on BeanEditFromPage (UpdateExisting).
}
...
}
24 May 2007
TSA504.pages.AddNew - Step 04
Refers to... .
package org.example.TSA504.pages;
import org.apache.tapestry.annotations.Component;
import org.apache.tapestry.annotations.Inject;
import org.apache.tapestry.annotations.Persist;
import org.apache.tapestry.corelib.components.Form;
import org.apache.tapestry.corelib.components.PasswordField;
import org.apache.tapestry.corelib.components.TextField;
import org.example.TSA504.beans.TUser;
import org.example.TSA504.services.interfaces.UserAuthenticator;
public class AddNew
{
@Persist
private String _newUserName;
private String _newFirstUserName;
private String _newLastUserName;
private String _newMI;
private String _newEmail;
private String _newPassword;
private String _confirmNewPassword;
@Component(id = "newUserName")
private TextField _newUserNameField;
@Component(id = "confirmNewPassword")
private PasswordField _confirmNewPasswordField;
@Component
private Form _regform;
@Inject
private UserAuthenticator _authenticator;
String onSuccess() {
if (!_confirmNewPassword.equals(_newPassword))
{
_regform.recordError(_confirmNewPasswordField, "Passwords don't match.");
return null;
}
if (!(_authenticator.addNewTUser(new TUser (_newUserName, _newFirstUserName,_newLastUserName,_newMI,_newEmail,_newPassword)))){
_regform.recordError(_newUserNameField, "Sorry, a error has occured upon adding the user");
return null;
}
return "Start";
}
/**
* @return the _confirmpassword
*/
public String getConfirmNewPassword() {
return _confirmNewPassword;
}
/**
* @param _confirmpassword the _confirmpassword to set
*/
public void setConfirmNewPassword(String _confirmpassword) {
this._confirmNewPassword = _confirmpassword;
}
/**
* @return the _confirmNewPasswordField
*/
public PasswordField getConfirmNewPasswordField() {
return _confirmNewPasswordField;
}
/**
* @param field the _confirmNewPasswordField to set
*/
public void setConfirmNewPasswordField(PasswordField field) {
_confirmNewPasswordField = field;
}
/**
* @return the _newPassword
*/
public String getNewPassword() {
return _newPassword;
}
/**
* @param _newPassword the _newPassword to set
*/
public void setNewPassword(String _password) {
this._newPassword = _password;
}
/**
* @return the _regform
*/
public Form getRegform() {
return _regform;
}
/**
* @param _regform the _regform to set
*/
public void setRegform(Form _regform) {
this._regform = _regform;
}
/**
* @return the _newUserName
*/
public String getNewUserName() {
return _newUserName;
}
/**
* @param name the _newUserName to set
*/
public void setNewUserName(String name) {
_newUserName = name;
}
/**
* @return the _newEmail
*/
public String get_newEmail() {
return _newEmail;
}
/**
* @return the _newFirstUserName
*/
public String get_newFirstUserName() {
return _newFirstUserName;
}
/**
* @return the _newLastUserName
*/
public String get_newLastUserName() {
return _newLastUserName;
}
/**
* @return the _newMI
*/
public String get_newMI() {
return _newMI;
}
/**
* @param email the _newEmail to set
*/
public void set_newEmail(String email) {
_newEmail = email;
}
/**
* @param firstUserName the _newFirstUserName to set
*/
public void set_newFirstUserName(String firstUserName) {
_newFirstUserName = firstUserName;
}
/**
* @param lastUserName the _newLastUserName to set
*/
public void set_newLastUserName(String lastUserName) {
_newLastUserName = lastUserName;
}
/**
* @param _newmi the _newMI to set
*/
public void set_newMI(String _newmi) {
_newMI = _newmi;
}
/**
* @return the _newUserNameField
*/
public TextField get_newUserNameField() {
return _newUserNameField;
}
/**
* @param userNameField the _newUserNameField to set
*/
public void set_newUserNameField(TextField userNameField) {
_newUserNameField = userNameField;
}
}
package org.example.TSA504.pages;
import org.apache.tapestry.annotations.Component;
import org.apache.tapestry.annotations.Inject;
import org.apache.tapestry.annotations.Persist;
import org.apache.tapestry.corelib.components.Form;
import org.apache.tapestry.corelib.components.PasswordField;
import org.apache.tapestry.corelib.components.TextField;
import org.example.TSA504.beans.TUser;
import org.example.TSA504.services.interfaces.UserAuthenticator;
public class AddNew
{
@Persist
private String _newUserName;
private String _newFirstUserName;
private String _newLastUserName;
private String _newMI;
private String _newEmail;
private String _newPassword;
private String _confirmNewPassword;
@Component(id = "newUserName")
private TextField _newUserNameField;
@Component(id = "confirmNewPassword")
private PasswordField _confirmNewPasswordField;
@Component
private Form _regform;
@Inject
private UserAuthenticator _authenticator;
String onSuccess() {
if (!_confirmNewPassword.equals(_newPassword))
{
_regform.recordError(_confirmNewPasswordField, "Passwords don't match.");
return null;
}
if (!(_authenticator.addNewTUser(new TUser (_newUserName, _newFirstUserName,_newLastUserName,_newMI,_newEmail,_newPassword)))){
_regform.recordError(_newUserNameField, "Sorry, a error has occured upon adding the user");
return null;
}
return "Start";
}
/**
* @return the _confirmpassword
*/
public String getConfirmNewPassword() {
return _confirmNewPassword;
}
/**
* @param _confirmpassword the _confirmpassword to set
*/
public void setConfirmNewPassword(String _confirmpassword) {
this._confirmNewPassword = _confirmpassword;
}
/**
* @return the _confirmNewPasswordField
*/
public PasswordField getConfirmNewPasswordField() {
return _confirmNewPasswordField;
}
/**
* @param field the _confirmNewPasswordField to set
*/
public void setConfirmNewPasswordField(PasswordField field) {
_confirmNewPasswordField = field;
}
/**
* @return the _newPassword
*/
public String getNewPassword() {
return _newPassword;
}
/**
* @param _newPassword the _newPassword to set
*/
public void setNewPassword(String _password) {
this._newPassword = _password;
}
/**
* @return the _regform
*/
public Form getRegform() {
return _regform;
}
/**
* @param _regform the _regform to set
*/
public void setRegform(Form _regform) {
this._regform = _regform;
}
/**
* @return the _newUserName
*/
public String getNewUserName() {
return _newUserName;
}
/**
* @param name the _newUserName to set
*/
public void setNewUserName(String name) {
_newUserName = name;
}
/**
* @return the _newEmail
*/
public String get_newEmail() {
return _newEmail;
}
/**
* @return the _newFirstUserName
*/
public String get_newFirstUserName() {
return _newFirstUserName;
}
/**
* @return the _newLastUserName
*/
public String get_newLastUserName() {
return _newLastUserName;
}
/**
* @return the _newMI
*/
public String get_newMI() {
return _newMI;
}
/**
* @param email the _newEmail to set
*/
public void set_newEmail(String email) {
_newEmail = email;
}
/**
* @param firstUserName the _newFirstUserName to set
*/
public void set_newFirstUserName(String firstUserName) {
_newFirstUserName = firstUserName;
}
/**
* @param lastUserName the _newLastUserName to set
*/
public void set_newLastUserName(String lastUserName) {
_newLastUserName = lastUserName;
}
/**
* @param _newmi the _newMI to set
*/
public void set_newMI(String _newmi) {
_newMI = _newmi;
}
/**
* @return the _newUserNameField
*/
public TextField get_newUserNameField() {
return _newUserNameField;
}
/**
* @param userNameField the _newUserNameField to set
*/
public void set_newUserNameField(TextField userNameField) {
_newUserNameField = userNameField;
}
}
8 May 2007
TSA503.pages.Login - Step 01
Step 01 Login.java
package org.example.TSA503.pages;
import org.apache.tapestry.annotations.*;
import org.apache.tapestry.corelib.components.*;
/**
* 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
// private UserAuthenticator _authenticator; // Don't need this for now.
@Component(id = "password")
private PasswordField _passwordField;
@Component
private Form _form;
String onSuccess()
{
// if (!_authenticator.isValid(_userName, _password)) // Don't need this for now.
if (!_userName.equals(_password))
{
_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;
}
}
package org.example.TSA503.pages;
import org.apache.tapestry.annotations.*;
import org.apache.tapestry.corelib.components.*;
/**
* 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
// private UserAuthenticator _authenticator; // Don't need this for now.
@Component(id = "password")
private PasswordField _passwordField;
@Component
private Form _form;
String onSuccess()
{
// if (!_authenticator.isValid(_userName, _password)) // Don't need this for now.
if (!_userName.equals(_password))
{
_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;
}
}
Subscribe to:
Posts (Atom)