2007-05-09

SimpleTapestry 5 CRUD application -Step 02, adding a service.

Assuming Step 01, let's change Login page class a bit. Find and uncomment following lines with the «// Don't need this for now.»:

@Inject
private UserAuthenticator _authenticator;

and

if (!_authenticator.isValid(_userName, _password))

Then, just delete the line

if (!_userName.equals(_password))

So, here is the result , our new Login.java.

At this moment we have UserAuthenticator undefined, so let's create it – select NEW->Interface ->package = org.example.TSA503.services.interfaces, name= UserAuthenticator . The interface body is simple:

public interface UserAuthenticator {
public
boolean isValid(String userName, String pwd);
}

Now, we have to create implementation of the interface, UserAuthenticatorImpl class – NEW-Class->package=org.example.TSA503.services, name=UserAuthenticatorImpl , implements UserAuthenticator of course.

The code is also simple:

public class UserAuthenticatorImpl implements UserAuthenticator {
public boolean isValid(String userName, String pwd) {
if (userName.equalsIgnoreCase(pwd)){
return true;
}
return false;
}
}

Open your Login.java and add such an import: org.example.TSA503.services.interfaces.UserAuthenticator

Save the project and run it on jetty, open the link http://localhost:8080/TSA503/login and ...

something wrong, just because

java.lang.ClassNotFoundException: caught an exception while obtaining a class file for org.example.TSA503.pages.Login

can't be a Login page. So, let's do some additional work and notify Tapestry about our UserAuthenticator service, open /TSA503/src/main/java/org/example/TSA503/services/AppModule.java and append following to it:

public static UserAuthenticator buildUserAuthenticator()
{
return new UserAuthenticatorImpl();
}

Also, add such an import:

import org.example.TSA503.services.interfaces.UserAuthenticator;

And now - run the jetty again and open http://localhost:8080/TSA503/login - it must be fine at this time, so you can «test» the page, who knows, it may contains a lot of bugs.


6. SimpleTapestry 5 CRUD application -Step 06, tweaking a grid a bit.
5. Simple Tapestry 5 CRUD application - BeanEditForm and Grid screencasts aprobation.
4. SimpleTapestry 5 CRUD application -Step 04 Adding some basic Hibernate features into the project.
3. SimpleTapestry 5 CRUD application -Step 03, "user" bean creation.
2. SimpleTapestry 5 CRUD application -Step 02, adding a service.
1. SimpleTapestry 5 CRUD application -Step 01.

2 comments:

R. Sanders said...

Note that the authenticator code could be shortened to just


return userName.equalsIgnoreCase(pwd);

Лозован Евгений said...

Ok, thank you.