Reputation: 772
I am trying to access to an interface of constants from my jsp but it shows the following error.
Caused by: tag 'select', field 'list', name 'title':
The requested list key 'Constants.TITLE'
could not be resolved as a collection/array/map/enumeration/iterator type.
Example: people or people.{name} - [unknown location]
My interface
public interface Constants {
public List<String> TITLE = Arrays.asList("Mr","Mrs","Ms","Miss");
// public String[] TITLE = {"MR","MRs"}; << does not work as well
//public static final String[] TITLE = {"MR","MRs"}; << does not work as well
}
My Jsp Code
...
<%@page import="com.myconstants.Constants" %>
<head>
</head>
<body>
<s:form>
<s:select label="title" name="title" list="Constants.TITLE" value=" "/>
</s:form>
....
Upvotes: 1
Views: 1624
Reputation: 160321
Make a class. Put the list in a class. Use normal OGNL static property access:
<s:select key="title" list="@some.package.Constants@TITLES" />
Would I do it like this? Probably not; harder to I18Nize, harder to find/refactor usages in JSP (depends on IDE). In general I'd recommend exposing data to the view layer via a service/layer in actions.
Upvotes: 2