question from mail-list

Is there a way to set the default DateFormat for all DateField
elements of a BeanForm?
I know that I could specify the format in a <t:Parameter /> block for
the form. But then I'd have to do this on every occurrence of a Date
Is there maybe some service that I could intercept when it is creating
DateField instances and tell it what format to use?

possible solution

create or add to application's global properties : %d.%m.%Y

add the class AppPropertyEditBlocks in your page subpackage

public class AppPropertyEditBlocks
    private PropertyEditContext _context;

     * get the context of the bean editor.
     * @return the context of the bean editor
    public PropertyEditContext getContext()
        return _context;

    @Component(parameters = {"value=context.propertyValue", "label=prop:context.label", "clientId=prop:context.propertyid",
            "validate=prop:dateFieldValidator", "format=prop:dateFieldFormat"})
    private DateField _dateField;

    public String getDateFieldFormat()
        String dateFieldFormater = "%m/%d/%y";

        if (_messages.contains(""))
            dateFieldFormater = _messages.get("");

        return dateFieldFormater;

    public FieldValidator getDateFieldValidator()
        return _context.getValidator(_dateField);

add the tml-template AppPropertyEditBlocks.tml in your page subpackage

<div xmlns:t="">

    <t:block id="date">
        <t:label for="dateField"/>
        <input t:id="dateField"/>


add to your IoC configuration the contributeBeanBlockSource method like this:

public class Tap5ComponentsModule
    public static void contributeBeanBlockSource(Configuration<BeanBlockContribution> configuration)
        configuration.add(new BeanBlockContribution("date", "AppPropertyEditBlocks", "date", true));

and restart your application,.... voila!

Tapestry5LocalizedDateField (last edited 2009-09-20 23:20:14 by localhost)