CVS: TapestryBook/examples/src/examples/dates Dates2.java,NONE,1.1

Howard Lewis Ship <[email protected]> Mon, 03 Mar 2003 17:13:13 -0800
Newsgroups gmane.comp.java.tapestry.cvs
Message-ID <[email protected]>
Update of /cvsroot/tapestry/TapestryBook/examples/src/examples/dates
In directory sc8-pr-cvs1:/tmp/cvs-serv3222/examples/src/examples/dates

Added Files:
	Dates2.java 
Log Message:
Add new examples for Upload and DatePicker.

--- NEW FILE: Dates2.java ---
package examples.dates;

import java.util.Date;

import net.sf.tapestry.IRequestCycle;
import net.sf.tapestry.form.IFormComponent;
import net.sf.tapestry.html.BasePage;
import net.sf.tapestry.valid.IValidationDelegate;
import net.sf.tapestry.valid.ValidationConstraint;

public abstract class Dates2 extends BasePage
{
    public abstract Date getStartDate();
    public abstract Date getEndDate();

    protected void error(
        IValidationDelegate delegate,
        String componentId,
        String message,
        ValidationConstraint constraint)
    {
        IFormComponent component = (IFormComponent) getComponent(componentId);

        delegate.setFormComponent(component);
        delegate.record(message, constraint);
    }

    public void formSubmit(IRequestCycle cycle)
    {
        IValidationDelegate delegate = (IValidationDelegate) getBeans().getBean("delegate");

        Date startDate = getStartDate();
        Date endDate = getEndDate();

        if (startDate == null)
            error(delegate, "inputStart", "Start Date is required.", ValidationConstraint.REQUIRED);

        if (endDate == null)
            error(delegate, "inputEnd", "End Date is required.", ValidationConstraint.REQUIRED);

        if (delegate.getHasErrors())
            return;

        if (startDate.after(endDate))
        {
            error(
                delegate,
                "inputEnd",
                "End Date must be after Start Date.",
                ValidationConstraint.CONSISTENCY);
            return;
        }

        DatesConfirm next = (DatesConfirm) cycle.getPage("DatesConfirm");
        next.setStartDate(startDate);
        next.setEndDate(endDate);
        cycle.setPage(next);
    }

}


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