Hi!

Maybe this helps:

We wrote our own component, modify as you like


public class DateFormatter
{
    @Inject private Messages_messages;

   @Parameter(required =true, defaultPrefix ="prop")private Date_date;
    @Parameter(required =false, defaultPrefix ="literal")private String_format;

    boolean beginRender(final MarkupWriter writer)
    {
        if (null !=_date) {
            try {
                if (null ==_format) {
                    _format ="yyyy-MM-dd HH:mm:ss";
                }
                final SimpleDateFormat sdf =new SimpleDateFormat(_format);
                writer.writeRaw(sdf.format(_date));
            }catch (final Exception e) {
                writer.writeRaw(_date.toString());
            }
        }

        // Abort the rest of the render. return false;
    }
}


and use it like this

<t:TOC.DateFormatter date="yourdatefield" format="${message:FORMAT.DateTime}"/>
where TOC is our Library Alias, replace accordingly.
And we provide different format setttings via our application message catalog 
like this

FORMAT.DateOnly =dd.MM.yyyy FORMAT.DateTime =dd.MM.yyyy - HH:mm:ss


Jens



Am 10.04.18 um 21:52 schrieb Thiago H. de Paula Figueiredo:
Hi!

Your question was clear. There's no such configuration symbol due to the
way way DateField defines which format to use, which is calling
DateFormat.getDateInstance(DateFormat.SHORT, locale).

A possibility is to create your own DateField class by copying the source
from the Tapestry one, customizing it to your needs and contributing it to
the ComponentOverride service. Something like this, not tested:

public static void contributeComponentOverride(MappedConfiguration<Class,
Class> configuration) {
     configuration.add(DateField.class, YourDateField.class);
}

Doing this, Tapestry will use YourDateField instead of DateField when you
have a <t:datefield> or <input t:type="DateField">.

On Tue, Apr 10, 2018 at 1:04 PM, abangkis <abang...@gmail.com> wrote:

Hi thiago,

Sorry, i'm having a bit of trouble understanding your explanation.

Lets say i pick April 10th, 2018 from my date picker in my page. It will
fill the field with 04/10/2018.  While the format we expected is
10-04-2018. I could override the field and specify the format in the
template

<t:datefield t:id="birthdate" value="borrower?.birthdate"
*format="dd-MM-yyyy"* t:mixins="formgroup"/>

but that means i have to do this for every datepicker i have.

I was thinking maybe there's some kind of contribution that I can override
in the app module. Something like

@Contribute(DateField.class)
public static void overrideDefaultFormat(MappedConfiguration
configuration)
{

configuration.add(SymbolConstants.DATEFIELD_DEFAULT_FORMAT, "dd-MM-yyyy");
}

I hope this clear up my question.

Regards


On Tue, Apr 10, 2018 at 8:17 PM, Thiago H. de Paula Figueiredo <
thiag...@gmail.com> wrote:

Hello!

The default format is taken from
DateFormat.getDateInstance(DateFormat.SHORT, locale), where locale is
got
through @Inject. Is your desired date format the one returned by that
method for your locale?

On Tue, Apr 10, 2018 at 5:26 AM, abangkis <abang...@gmail.com> wrote:

Hi, is there a quick way to override tapestry datefield default format?
In
a single datefield i can do

<t:datefield t:id="birthdate" value="borrower?.birthdate"
format="dd-MM-yyyy"
     t:mixins="formgroup"/>

But it became very repetitive for many pages.

Regards



--
http://www.mreunionlabs.net/ <http://www.mreunion-labs.net/>
twitter : @mreunionlabs @abangkis
page : https://plus.google.com/104168782385184990771



--
Thiago



--
http://www.mreunionlabs.net/ <http://www.mreunion-labs.net/>
twitter : @mreunionlabs @abangkis
page : https://plus.google.com/104168782385184990771




Reply via email to