users@javaserverfaces.java.net

Re: How do I define a function to be used with Unified Expression Language in JSF?

From: Mikael Andersson <mail.micke_at_gmail.com>
Date: Wed, 19 Mar 2008 11:20:01 +0000

This is probably not the answer you are after, because it is Facelets
specific.

In Facelets however it is easy to create your own EL functions and in the
end you would have something like this:

<h:outputText value="#{myfuncs:myClientTime(row.clientCreated)}"/>

You will find the Facelets developer docs on this page:
facelets.dev.java.net

And here is a nice turorial of how to create Facelets functions:
http://www-128.ibm.com/developerworks/java/library/j-facelets2.html

Note: the example above loads all static methods in a class and makes them
available as functions, you can just as easily (or perhaps easier) define
the functions you want in an xml file( for instance using static helper
methods in your favourite commons project).

Cheers,
 Micke

On 18/03/2008, Todd Patrick <Todd.Patrick_at_dtn.com> wrote:
>
> I'm Reading the section "Unified Expression Language" in the Java EE
> Tutorial.
>
> The JSP expression language allows you to define a function that can be
> invoked in an
> expression.
>
> What I'd like to do is the following:
>
> 1.) Within a h:dataTable I have a JSF component that looks like this:
>
> <h:dataTable var="row" value="#{mybean.clientList}">
> ...
> <h:outputText value="#{row.clientCreated}"/>
>
> "mybean" is in request scope and the clientList is a List<Client>. The
> clientCreated property returns a Long which is the milliseconds of the
> Date Time of when the Client was added.
>
>
> 2.) I have a public String method in the same "mybean" that converts
> milliseconds to a human readable date time format.
>
> public String myClientTime(Long milliseconds){
> }
>
>
> 3.) Is it possible to do something like this?
>
> <h:dataTable var="row" value="#{mybean.clientList}">
> ...
> <h:outputText value="#{mybean.myClientTime(row.clientCreated)}"/>
>
>
> I don't control the List<Client> that is provided to the value of the
> h:dataTable, so I can't convert the milliseconds to a human readable
> format before I display the value in the h:outputText component.
>
> I appreciate any suggestions on the best way to do this.
>
> Thanks,
>
> --Todd
>
>
> Todd Patrick
> Web Developer
> DTN
> 9110 West Dodge Road, Suite 200
> Omaha, NE 68114
>
> todd.patrick_at_dtn.com
> Phone: 402-255-8155
> Fax: 402-255-8825
> www.dtn.com
> DTN Smarter Decisions
>
> -----------------------------------------
> NOTICE: This email message is for the sole use of the intended
> recipient(s) and may contain confidential and privileged
> information. Any unauthorized use, disclosure or distribution is
> prohibited. If you are not the intended recipient, please contact
> the sender by reply email and destroy all copies of the original
> message.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_javaserverfaces.dev.java.net
> For additional commands, e-mail: users-help_at_javaserverfaces.dev.java.net
>
>