You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Scot Mcphee <sc...@gmail.com> on 2009/08/24 13:10:37 UTC

Bean models?

I've got a class, that is ever only display-only. I need to show the
date in the class in a specific format. What I cannot see how to do,
is specify the format for the date of this class. I've had a look at
the BeanModel documentation but I can't see how I make it work, the
discussion I find about it seems to include just adding/removing
fields and things like that. Also, I don't want to have change every
page it's displayed on. I want to write a component for this class;
but I can't see how to make it's bean model format the date right. All
the discussion I find on google about date formatting is always about
the fancy date input control, which I don't care about - the user
never inputs dates.

Is there good doco about this anywhere?

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


Re: Bean models?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
<t:beandisplay object="message">
         <p:messageTimestamp>
             ${messageTimestamp}
         </p:messageTimestamp>
     </t:beandisplay>

In your component class or template:

public String getMessageTimestamp() {
	return dateFormat.format(message.getMessageTimestamp());
}

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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


Re: Bean models?

Posted by Scot Mcphee <sc...@gmail.com>.
2009/8/24 Thiago H. de Paula Figueiredo <th...@gmail.com>:

>
> One solution is to provide a new view block for your class dates. You'll
> need to implement a DataTypeAnalyzer, return a "formatteddate" type for your
> class dats, contribute it to the DataTypeAnalyzer service, then provide a
> view and an edit block for it. Take a look at TapestryModule to find some
> examples.
>

OK thanks I'll dig around those tips.

I did hit on a very simple solution for the moment - componentise the
display and  in it's template;

<t:beandisplay object="message">
        <p:messageTimestamp>
            ${message.messageTimestamp}
        </p:messageTimestamp>
    </t:beandisplay>

But that gives date.toString() style output which is less than ideal
but got me breathing space to look at a better solution as per your
suggestions. I guess another way is to use t:output with a formatter
configured in the component.

It strikes me that maybe there just needs to to be a way to globally
format dates (or specifiy the default)  in the style of a
java.text.dateformat template. For example one of the things I tried
was adding messageTimestamp-format entries to the relevant .properties
file for the page to see if that worked, but it did not.

thanks
scot

-- 
let x=x - http://crazymcphee.net/x/
xray dubs - http://autonomous.org/music/

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


Re: Bean models?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Mon, 24 Aug 2009 08:10:37 -0300, Scot Mcphee <sc...@gmail.com>  
escreveu:

> I've got a class, that is ever only display-only. I need to show the
> date in the class in a specific format. What I cannot see how to do,
> is specify the format for the date of this class.

The format used by Grid and BeanDisplay to format dates is defined by the  
date Tapestry data type and its corresponding view block. Looking at  
PropertyDisplayBlocks source, the format used is  
DateFormat.getDateInstance(DateFormat.MEDIUM, locale). We could add a JIRA  
asking for some way to provide your own date formatter (maybe some service  
with a default implementantion that we can override).

One solution is to provide a new view block for your class dates. You'll  
need to implement a DataTypeAnalyzer, return a "formatteddate" type for  
your class dats, contribute it to the DataTypeAnalyzer service, then  
provide a view and an edit block for it. Take a look at TapestryModule to  
find some examples.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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