20 September 2007

Step 08 org.example.TSA.value - SessionData

Step 08
SessionData
is an object to store userName and sessionExists flag between pages, so if a session doesn't exist then user will be redirected t Login page.

package org.example.TSA.value;

public class SessionData {
private String _userName;
private boolean sessionExists;

/**
* @return the sessionExists
*/
public boolean isSessionExists() {
return sessionExists;
}
/**
* @param exists the sessionExists to set
*/
public void setSessionExists(boolean exists) {
sessionExists = exists;
}
/**
* @return the userName
*/
public String getUserName() {
return _userName;
}
/**
* @param userName the userName to set
*/
public void setUserName(String userName) {
this._userName = userName;
}
}

Step 08 , org.example.TSA.pages.spages - LoginProtected

Step 08
Base (super) page class for pages which require checking whether user has logged in or not.


package org.example.TSA.pages.spages;


import org.apache.tapestry.annotations.ApplicationState;
import org.example.TSA.value.SessionData;
public abstract class LoginProtected {
@ApplicationState
private SessionData _session;

Object onActivate() {
if(!_session.isSessionExists()){
return "Login";
}
return null;
}

/**
* @return the _session
*/
public SessionData get_session() {
return _session;
}
}

21 July 2007

TSA504.pages.UpdateExisting - Step 06

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;
}
}

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>

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;
}
}

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>

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).
}

...
}