We have had success with creating our own ValidationDelegate Class and then 
passing that whereever it is needed.  There are times when we don't have access 
to the one in the page or when we want to get errors without displaying them...

import java.util.ArrayList;

import org.apache.tapestry.valid.ValidationConstraint;

public class SummaryInfoValidationDelegate
extends ValidationDelegate
{
    private ArrayList<String> errorMsgs = new ArrayList<String>();;
    
    public ArrayList<String> getErrorMsgs()
    {
        return errorMsgs;
    }
    
    public boolean hasErrorMsgs()
    {
        if (errorMsgs.size() > 0)
        {
            return true;
        }
        
        return false;
    }
    
    public void record(String error, ValidationConstraint v)
    {
        errorMsgs.add(error);
    }
    
    public void wipeErrorMsgs()
    {
        errorMsgs = new ArrayList<String>();
    }
}

hth,

Mark


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Tue 1/24/2006 1:47 PM
To: Tapestry users
Subject: unit testing
 
Hi everyone,

many thanks for all who produce the framework.

for our current project we move to version 4. among many other
improvements, the input validation seems much cleaner now,
so we want to use it.

implemented our custom ValidationDelegate. no problem here. next, 
we want a message block above the form, implemented somehow 
like this:

public void submitForm(IRequestCycle cycle) {

  List errormsgs = new ArrayList();
  IValidationDelegate delegate = (IValidationDelegate) 
getBeans().getBean("delegate");
  if (delegate.getHasErrors()) {
    List ftlst = delegate.getFieldTracking();
    for (int i = 0; i < ftlst.size(); i++) {
      IFieldTracking ft = (IFieldTracking) ftlst.get(i);
      if (ft.isInError()) {
        errormsgs.add(ft.getErrorRenderer().toString());
      }
    }
  }
  ...
}

this causes a problem with the unit testing. the 'Creator' creates 
the class but the 'getBeans()' method doesn't seem to exist and i 
surely don't know howto set the IBeanProvider and even less
howto maybe prepare and set the 'IValidationDelegate'.

any ideas?

Thanks,
Carst
-- 
Carsten Heinrigs
Ocean-7 Development
Tel: 212 533-8460



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Reply via email to