You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by James Iry <ja...@hotmail.com> on 2003/10/15 23:39:09 UTC

RE: Submit from one form, re-process from another

Still not really able to submit off of one form and then re-process errors
on another form.
 
I've got a reusable LoginComponent for the small form that lives on the Home
page and a Login for the full blown option with error messages, lost
passwords, etc.   The Login page is working exactly as desired, but the
component is not.  The component's listener method looks like this:
 
 public void okSubmit(IRequestCycle cycle) {
  LoginPage page = LoginPage.activate(cycle, null);
  page.setLogin(getLogin());
  page.setPassword(getPassword());
  page.okSubmit(cycle);
 }

The LoginPage's listener looks like this:
 
 public void okSubmit(IRequestCycle cycle) {
  IValidationDelegate delegate = getValidationDelegate();
 
  // If no form errors try to login, otherwise stay on this page and 
  // let the fields show their errors.  
  User user = null;
  if (!delegate.getHasErrors()) {
   user = attemptLogin(cycle);
  }  
  
  if (user == null) {
   doFailedLogin();
  } else {
   doSuccessfulLogin(cycle, user);
  }  
 }

The problem is that delegate.getHasErrors() is always returning false, no
matter what the field values are.  Also, on a failed login, the system tries
to set an error on the password field, but that causes a null pointer
exception at ValidationDelegate.record().  Here's the code that throws the
exception
 
 private void setErrorField(String componentId, String message)
 {
  IFormComponent field = (IFormComponent) getComponent(componentId);
 
  IValidationDelegate delegate = getValidationDelegate();
  delegate.setFormComponent(field);
  delegate.record(new ValidatorException(message));
 } 

Here's a snip of the stack trace from the NullPointerException
*
org.apache.tapestry.valid.ValidationDelegate.getComponentTracking(Validation
Delegate.java:161) 

*
org.apache.tapestry.valid.ValidationDelegate.findCurrentTracking(ValidationD
elegate.java:316) 

*
org.apache.tapestry.valid.ValidationDelegate.record(ValidationDelegate.java:
269) 

*
org.apache.tapestry.valid.ValidationDelegate.record(ValidationDelegate.java:
247) 

*
org.apache.tapestry.valid.ValidationDelegate.record(ValidationDelegate.java:
233) 

*	com.asc.ui.user.LoginPage.setErrorField(LoginPage.java:164) 
 
Clearly the ValidationDelegate isn't in a state where it's ready to validate
or record errors.   In fact, adding a 
call to ValidationDelegate.recordFieldInputValue(String) to force the
delegate to hold the value of the login or password causes a similar null
pointer exception.  How can I get the ValidationDelegate to be in the right
state to validate inputs that came from another form?  Or is this the right
approach at all?

-----Original Message-----
From: James Iry [mailto:jamesiry@hotmail.com] 
Sent: Tuesday, October 07, 2003 11:58 AM
To: tapestry-user@jakarta.apache.org
Subject: Submit from one from, re-process from another



Hi, 

I'm looking for a good, elegant, Tapestry friendly way of submitting info
from one form and re-processing it on another if there's an error.  Some
background:

I've got a Login page with Form that has two ValidFields (username and
password) and a submit button.  The form uses a ValidationDelegate so it has
the ability to display errors, highlight fields that have problems, and
select the first field with an error.  The page also has all the standard
links for forgotten passwords and for joining the web site.  This all works
very well, and Tapestry has made it soooo much easier to build such a rich
interaction.

In addition, though, I'd like to give users the option of logging in from
the Home page (and several other pages) without clicking a link to the Login
page.  On those pages, I don't want to allocate valuable real-estate for
error messages, forgotten password links, etc.  Ideally, the Home page would
have 2 fields and a submit button.  If the user enters valid credentials,
they're logged on and moved to the appropriate section of the site.  If
there's any problem with the form at all, I'd like to show the Login page
and let it handle displaying the error message(s), re-displaying the
username they entered, etc.

Any thoughts on how to do this?  In particular, I'm not sure how to get the
ValidationDelegate on the Login page to be in sync with data that was
submitted from another form.