You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Aristedes Maniatis <ar...@ish.com.au> on 2014/05/14 08:24:16 UTC

formatting attributes

I understand that I can do this in the tml:

    <span itemprop="startDate"><t:output value="someDate" format="literal:YYYY-MM-DD hh:mm:ss 'UTC' Z"></span>


But I want to put the value into an attribute to suit a Google schema microformat, like this:

<abbr itemprop="startDate" content="${format:date=YYYY-MM-DD hh:mm:ss 'UTC' Z,someDate}" title="">


This does not work. What am I missing here?


Ari Maniatis


-- 
-------------------------->
Aristedes Maniatis
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: formatting attributes

Posted by Lance Java <la...@googlemail.com>.
If you really want this feature then you can write a custom binding prefix.
It can work exactly as you want

> I'm trying to steer our team away from embedding style and formatting in
Java code

Well, you need to either do it in the template or in the Java code. Both
the template and the component class are for presentation logic so I don't
see a problem putting it there. The added benefit is its easier to test.

Horses for courses I guess...
 On 17 May 2014 00:00, "Aristedes Maniatis" <ar...@ish.com.au> wrote:

> Lance Java wrote:
> > I'm not sure how you have assumed that tapestry knows how understand a
> "format:" binding prefix. Certainly none of the tapestry documentation
> mentions it?
>
> I was trying to extrapolate from this:
> http://wiki.apache.org/tapestry/Tapestry5HowToFormatDateTimeEtc
>
> Really, I wasn't hopeful it would work so much as provide an example for
> what I'm trying to accomplish.
>
>
> > The simple solution is to provide a getter for the formatted date String.
>
>
> This is the exact thing I am trying to avoid. Our development team has
> dozens of formatted strings scattered through Java and every time a design
> change requires a small formatting alteration we have to rebuild the
> application.
>
> I am not a tapestry expert, but I'm trying to steer our team away from
> embedding style and formatting in Java code and instead make it easily
> customisable in the tml files. In Rails, I'd do this no matter whether this
> was in an element or attribute:
>
> <%= someDate.strftime("%m/%d/%Y") %>
>
>
> In Spring/jstl I think there is <fmt:formatDate>.
>
>
> Cheers
> Ari
>
>
>
>
>
> On 14/05/2014 4:24pm, Aristedes Maniatis wrote:
> > I understand that I can do this in the tml:
> >
> >     <span itemprop="startDate"><t:output value="someDate"
> format="literal:YYYY-MM-DD hh:mm:ss 'UTC' Z"></span>
> >
> >
> > But I want to put the value into an attribute to suit a Google schema
> microformat, like this:
> >
> > <abbr itemprop="startDate" content="${format:date=YYYY-MM-DD hh:mm:ss
> 'UTC' Z,someDate}" title="">
> >
> >
> > This does not work. What am I missing here?
> >
> >
> > Ari Maniatis
> >
> >
>
> --
> -------------------------->
> Aristedes Maniatis
> ish
> http://www.ish.com.au
> Level 1, 30 Wilson Street Newtown 2042 Australia
> phone +61 2 9550 5001   fax +61 2 9550 4001
> GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: formatting attributes

Posted by Robert Zeigler <ro...@roxanemy.com>.
Why not specify the format to use in the i18n properties file for the template? Then your java code can read in the date string from he property file. Tapestry makes this über simple, just inject the Messages object (see http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/Messages.html). Then you can have different formatting for different locales automatically, you can change the format without a recompile/rebuild, etc. 

Robert

GATAATGCTATTTCTTTAATTTTCGAA

> On May 15, 2014, at 10:19 PM, Aristedes Maniatis <ar...@ish.com.au> wrote:
> 
> Lance Java wrote:
>> I'm not sure how you have assumed that tapestry knows how understand a "format:" binding prefix. Certainly none of the tapestry documentation mentions it?
> 
> I was trying to extrapolate from this: http://wiki.apache.org/tapestry/Tapestry5HowToFormatDateTimeEtc
> 
> Really, I wasn't hopeful it would work so much as provide an example for what I'm trying to accomplish.
> 
> 
>> The simple solution is to provide a getter for the formatted date String.
> 
> 
> This is the exact thing I am trying to avoid. Our development team has dozens of formatted strings scattered through Java and every time a design change requires a small formatting alteration we have to rebuild the application.
> 
> I am not a tapestry expert, but I'm trying to steer our team away from embedding style and formatting in Java code and instead make it easily customisable in the tml files. In Rails, I'd do this no matter whether this was in an element or attribute:
> 
> <%= someDate.strftime("%m/%d/%Y") %>
> 
> 
> In Spring/jstl I think there is <fmt:formatDate>.
> 
> 
> Cheers
> Ari
> 
> 
> 
> 
> 
>> On 14/05/2014 4:24pm, Aristedes Maniatis wrote:
>> I understand that I can do this in the tml:
>> 
>>    <span itemprop="startDate"><t:output value="someDate" format="literal:YYYY-MM-DD hh:mm:ss 'UTC' Z"></span>
>> 
>> 
>> But I want to put the value into an attribute to suit a Google schema microformat, like this:
>> 
>> <abbr itemprop="startDate" content="${format:date=YYYY-MM-DD hh:mm:ss 'UTC' Z,someDate}" title="">
>> 
>> 
>> This does not work. What am I missing here?
>> 
>> 
>> Ari Maniatis
> 
> -- 
> -------------------------->
> Aristedes Maniatis
> ish
> http://www.ish.com.au
> Level 1, 30 Wilson Street Newtown 2042 Australia
> phone +61 2 9550 5001   fax +61 2 9550 4001
> GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: formatting attributes

Posted by Aristedes Maniatis <ar...@ish.com.au>.
Lance Java wrote:
> I'm not sure how you have assumed that tapestry knows how understand a "format:" binding prefix. Certainly none of the tapestry documentation mentions it?

I was trying to extrapolate from this: http://wiki.apache.org/tapestry/Tapestry5HowToFormatDateTimeEtc

Really, I wasn't hopeful it would work so much as provide an example for what I'm trying to accomplish.


> The simple solution is to provide a getter for the formatted date String. 


This is the exact thing I am trying to avoid. Our development team has dozens of formatted strings scattered through Java and every time a design change requires a small formatting alteration we have to rebuild the application.

I am not a tapestry expert, but I'm trying to steer our team away from embedding style and formatting in Java code and instead make it easily customisable in the tml files. In Rails, I'd do this no matter whether this was in an element or attribute:

<%= someDate.strftime("%m/%d/%Y") %>


In Spring/jstl I think there is <fmt:formatDate>.


Cheers
Ari





On 14/05/2014 4:24pm, Aristedes Maniatis wrote:
> I understand that I can do this in the tml:
> 
>     <span itemprop="startDate"><t:output value="someDate" format="literal:YYYY-MM-DD hh:mm:ss 'UTC' Z"></span>
> 
> 
> But I want to put the value into an attribute to suit a Google schema microformat, like this:
> 
> <abbr itemprop="startDate" content="${format:date=YYYY-MM-DD hh:mm:ss 'UTC' Z,someDate}" title="">
> 
> 
> This does not work. What am I missing here?
> 
> 
> Ari Maniatis
> 
> 

-- 
-------------------------->
Aristedes Maniatis
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: formatting attributes

Posted by Chris Poulsen <ma...@nesluop.dk>.
Sorry, apparently I didn't really read your question ;)

Can't you create a getter in your page to return what you need?




On Wed, May 14, 2014 at 2:09 PM, Chris Poulsen <ma...@nesluop.dk>wrote:

> You probably do not want the ${ } as that converts its contents into a
> string.
>
> --
> Chris
>
>
> On Wed, May 14, 2014 at 8:24 AM, Aristedes Maniatis <ar...@ish.com.au>wrote:
>
>> I understand that I can do this in the tml:
>>
>>     <span itemprop="startDate"><t:output value="someDate"
>> format="literal:YYYY-MM-DD hh:mm:ss 'UTC' Z"></span>
>>
>>
>> But I want to put the value into an attribute to suit a Google schema
>> microformat, like this:
>>
>> <abbr itemprop="startDate" content="${format:date=YYYY-MM-DD hh:mm:ss
>> 'UTC' Z,someDate}" title="">
>>
>>
>> This does not work. What am I missing here?
>>
>>
>> Ari Maniatis
>>
>>
>> --
>> -------------------------->
>> Aristedes Maniatis
>> ish
>> http://www.ish.com.au
>> Level 1, 30 Wilson Street Newtown 2042 Australia
>> phone +61 2 9550 5001   fax +61 2 9550 4001
>> GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>

Re: formatting attributes

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
>> content="${format:date=YYYY-MM-DD hh:mm:ss 'UTC' Z,someDate}

On Wed, 14 May 2014 09:09:25 -0300, Chris Poulsen <ma...@nesluop.dk>  
wrote:

> You probably do not want the ${ } as that converts its contents into a
> string.

The original poster didn't describe what he meant by "not work". Guys,  
please avoid saying something "doesn't work" without further details. It's  
too vague.

What I guess is the problem with the template snipped above is the lack of  
a 'format' binding prefix. There's an easy solution, which is even more  
recommended because it doesn't put logic in the template:

content="${formattedDate}"

public String getFormattedDate() {
	return // whatever you want.
}

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: formatting attributes

Posted by Chris Poulsen <ma...@nesluop.dk>.
You probably do not want the ${ } as that converts its contents into a
string.

-- 
Chris


On Wed, May 14, 2014 at 8:24 AM, Aristedes Maniatis <ar...@ish.com.au> wrote:

> I understand that I can do this in the tml:
>
>     <span itemprop="startDate"><t:output value="someDate"
> format="literal:YYYY-MM-DD hh:mm:ss 'UTC' Z"></span>
>
>
> But I want to put the value into an attribute to suit a Google schema
> microformat, like this:
>
> <abbr itemprop="startDate" content="${format:date=YYYY-MM-DD hh:mm:ss
> 'UTC' Z,someDate}" title="">
>
>
> This does not work. What am I missing here?
>
>
> Ari Maniatis
>
>
> --
> -------------------------->
> Aristedes Maniatis
> ish
> http://www.ish.com.au
> Level 1, 30 Wilson Street Newtown 2042 Australia
> phone +61 2 9550 5001   fax +61 2 9550 4001
> GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: formatting attributes

Posted by Jens Breitenstein <ma...@j-b-s.de>.
What about a component like this:

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());
             }
         }

         return false;
     }
}


Usage in TML:

<t:DateFormatter date="yourDateMemberHere" format="${message:format_TIME}"/>


Using "message" allows you to configure it easily without hardcoding it. 
Therefore in your global message catalog you can define:


App_de.properties:

...
format_DATE_TIME = dd.MM.yyyy - HH:mm:ss
format_DATE = dd.MM.yyyy
format_TIME = HH:mm:ss
...

In the example above your date will only render the time portion


Jens




Am 14.05.14 19:59, schrieb Lance Java:
> I'm not sure how you have assumed that tapestry knows how understand a
> "format:" binding prefix. Certainly none of the tapestry documentation
> mentions it?
>
> The simple solution is to provide a getter for the formatted date String.
>
> If you really want a "format:" binding prefix, you can create a custom
> binding prefix.
>   On 14 May 2014 18:31, "Aristedes Maniatis" <ar...@ish.com.au> wrote:
>
>> I understand that I can do this in the tml:
>>
>>      <span itemprop="startDate"><t:output value="someDate"
>> format="literal:YYYY-MM-DD hh:mm:ss 'UTC' Z"></span>
>>
>>
>> But I want to put the value into an attribute to suit a Google schema
>> microformat, like this:
>>
>> <abbr itemprop="startDate" content="${format:date=YYYY-MM-DD hh:mm:ss
>> 'UTC' Z,someDate}" title="">
>>
>>
>> This does not work. What am I missing here?
>>
>>
>> Ari Maniatis
>>
>>
>> --
>> -------------------------->
>> Aristedes Maniatis
>> ish
>> http://www.ish.com.au
>> Level 1, 30 Wilson Street Newtown 2042 Australia
>> phone +61 2 9550 5001   fax +61 2 9550 4001
>> GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: formatting attributes

Posted by Lance Java <la...@googlemail.com>.
I'm not sure how you have assumed that tapestry knows how understand a
"format:" binding prefix. Certainly none of the tapestry documentation
mentions it?

The simple solution is to provide a getter for the formatted date String.

If you really want a "format:" binding prefix, you can create a custom
binding prefix.
 On 14 May 2014 18:31, "Aristedes Maniatis" <ar...@ish.com.au> wrote:

> I understand that I can do this in the tml:
>
>     <span itemprop="startDate"><t:output value="someDate"
> format="literal:YYYY-MM-DD hh:mm:ss 'UTC' Z"></span>
>
>
> But I want to put the value into an attribute to suit a Google schema
> microformat, like this:
>
> <abbr itemprop="startDate" content="${format:date=YYYY-MM-DD hh:mm:ss
> 'UTC' Z,someDate}" title="">
>
>
> This does not work. What am I missing here?
>
>
> Ari Maniatis
>
>
> --
> -------------------------->
> Aristedes Maniatis
> ish
> http://www.ish.com.au
> Level 1, 30 Wilson Street Newtown 2042 Australia
> phone +61 2 9550 5001   fax +61 2 9550 4001
> GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>