On Thu, 2003-03-06 at 15:34, Ian Bicking wrote:
> class Component:
> # __init__ is entirely specific to your component
>
> def awake(self, servlet):
> self._servlet = servlet
> # and we also have direct accessors for requests, etc.,
> # like Page (and a sleep, of course)
>
> def respond(self):
> # And here we do the actual work
Now that I look at this interface, it's not nearly adequate. The more
challenging part of an interface like this is dealing with more complex
issues. A login component would be a much more challenging example.
But maybe that's not too hard. It might look like:
class Login(Component):
def __init__(self, userManager):
self._userManager = userManager
def awake(self, servlet):
Component.awake(self, servlet)
field = self.request().field
if field('_loginUsername_', None):
self.login(field('_loginUsername_'), field('_loginPassword_')
def login(self, username, password):
if self._userManager.verifyPassword(username, password):
user = self._userManager.userForUsername(username)
self.servlet().setUser(user)
else:
# But what here?
Writing the login form method is left to the reader. There's a problem
here, that the login method can't do what it needs to do. If the login
fails, it should present the login form again and have an error message
(depending on the security of the application, that message might be
"username or password incorrect" or "username does not exist", etc).
And even if login is successful, it's nice to have some message.
So that's two problems -- how does login provide feedback, and how does
it take over the servlet when necessary? And there's also a bit of
logic around using the login form, specifically, how should the servlet
indicate that the user needs to login? Just calling the login form
method and then returning from the servlet seems sub-optimal to me --
well, I *really* want to use an exception for that, because that's just
the Right Control Structure for this case. How does that exception
translate into this Login component taking over?
So three problems.
Ian
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger
for complex code. Debugging C/C++ programs can leave you feeling lost and
disoriented. TotalView can help you find your way. Available on major UNIX
and Linux platforms. Try it free. www.etnus.com
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss