Expression Language and Interfaces

I am not an expert on JSTL and expression language, so my question might be silly ...

I work with Spring MVC, and in my controller I:

@ModelAttribute("export_types") public ExportType[] getExportTypes() { return edService.getTypes(); } 

ExportType is a custom interface:

 public interface ExportType { String getName(); //... } 

On my page, I have:

 <c:forEach var="item" items="${export_types}"> <tr> <td><input type="checkbox" value="${item.name}"></td> <td>${item.name}</td> </tr> </c:forEach> 

But when I launch my web application, I get this temptation: javax.el.PropertyNotFoundException: Property 'name' not found on type java.lang.String

The strange thing is that the exception says on type java.lang.String , and not on the type ExportType . So my question is: can I use an expression language with interfaces?


NOTE 1

edService.getTypes() returns an array of ExportType[] with specific interface implementations.

Just for clarity, I have an abstract class that implements the ExportType interface. Concrete types inherit from this:

 public abstract class AbstractExportType implements ExportType { protected String name; protected AbstractExportType() { this.name = this.getClass().getSimpleName(); } @Override String getName(){ return this.name; } //... } 

NOTE 2

The controller method that forwards export.jsp is very simple:

 @RequestMapping(value = "/export", method = RequestMethod.GET) public String getExportForm() { return "jsp/export"; } 
+4
source share
1 answer

I do not think this has anything to do with interfaces. Most likely, as @doublep says, export_types is actually not ExportType[] . I tried to reproduce what you are doing and it works great.

0
source

Source: https://habr.com/ru/post/1416424/


All Articles