Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create a date value in Expression Language?

Is it possible to create a date value in JSTL Expression Language (EL) without using scriptlets? Here is a snippet of some of the legacy code I'm trying to refactor to only use EL.

<td><%=new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm z").format(new java.util.Date())%></td>

Apparently it prints out the current date and time. I know I can format a date using EL, but can I get a date using EL?

like image 242
bakoyaro Avatar asked Dec 22 '10 19:12

bakoyaro


People also ask

What is expression language?

An expression language is a language for creating a computer-interpretable representation of specific knowledge and may refer to: Advanced Boolean Expression Language, an obsolete hardware description language for hardware descriptions.

Why use expression language example?

An expression language makes it possible to easily access application data stored in JavaBeans components. For example, the JSP expression language allows a page author to access a bean using simple syntax such as ${name} for a simple variable or ${name.


2 Answers

I don't think you can do this in EL. But how about this, no scriptlets here

<jsp:useBean id="today" class="java.util.Date" scope="page" />
<fmt:formatDate value="${today}" pattern="MM.dd.yyyy" />
like image 177
Aravind Yarram Avatar answered Oct 14 '22 21:10

Aravind Yarram


Thid would be helpfull if you use spring webflow framework

if you define this on the flow.xml

<on-start>
    <set name="flowScope.now" value="new java.util.Date()" />
</on-start>

You can get the value like this

<fmt:formatDate value="#{now}" pattern="MM.dd.yyyy" />
like image 30
Federico Traiman Avatar answered Oct 14 '22 21:10

Federico Traiman