2

I am using spring mvc 3 and my controller is passing a List from the controller to the JSP:

List suitableMatches = new ArrayList(); ...//Some code that adds Files to this list model.addAttribute("lists", suitableMatches);

and in my jsp :

<tr>
<td class="readOnly">${list.name}</td>
<td class="readOnly">${idiomSearch.testCaseID}</td>
<td class="readOnly">${list.lastModified}</td>
<td class="readOnly"><a href="downloadFile.htm?testID=${list.name}">Download</a></td>
</tr>

But I am getting the error :

Error 500: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is javax.el.PropertyNotFoundException: Property 'lastModified' not found on type java.io.File

Can anyone tell me please ,how is it that list.lastModified is not working?

2 Answers 2

1

Depending on the version of the JSP Expression Language that your web server is using you might not be able to access non-getter methods with this syntax.

${list.name} works as File has a method called getName(). However, File does not have a method called getLastModified(), the method is just called lastModified() so you have to add brackets when calling a method that is not a getter.

So the code should read ${list.lastModified()} and you will need to use at least v2.2 of the EL jar so this will need to either be included explicitly in the web application or use a servlet container that already includes this library.

A good source for the el syntax can be found in stackoverflow's el tag description

1
  • Thank you @Andy, However I created a java bean with getters only, and in the constructor , I passed the date value I needed. Because lastModified would display only long value, which would not make sense to display on the screen, so I did this :'public class SuitableMatch { .. .. private final String dateCompleted; .. public SuitableMatch(File file, String testId, String testCaseId) {.. this.dateCompleted = new java.util.Date(file.lastModified()).toString(); .. }' Oct 24, 2012 at 23:47
1

you can use a combination of JSTL and expression language for this like

<jsp:useBean id="dateValue" class="java.util.Date"/>
<jsp:setProperty name="dateValue" property="time" value="${file.lastModified()}"/>

<fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss z" value="${dateValue}" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.