You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by DavidZaz <dz...@cait.org> on 2010/01/04 21:32:59 UTC

Accessing Static Constants from JSP in Struts 2.0.14

I'm trying to access a static constant from a JSP page in Struts 2.0.14, but
it is not working.

My JSP page:

<s:select list="@org.my.company.myClass@AVAILABLE_STATES" />

Java code:

package org.my.company;

import java.util.ArrayList;
import java.util.List;

public Class myClass {

public static final List<String> AVAILABLE_STATES = getStates();

public static final List<String> getStates() {
List<String> states = new ArrayList<String>();
states.add("New York");
return states;
}

When I try to access my jsp page, I receive the following error message:

Caused by: tag 'select', field 'list': The requested list key
'@org.my.company.myClass@AVAILABLE_STATES' could not be resolved as a
collection/array/map/enumeration/iterator type. Example: people or
people.{name} - [unknown location]

Does anyone have any suggestion about what needs to be changed?

Thanks!
-- 
View this message in context: http://old.nabble.com/Accessing-Static-Constants-from-JSP-in-Struts-2.0.14-tp27018870p27018870.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Accessing Static Constants from JSP in Struts 2.0.14

Posted by DavidZaz <dz...@cait.org>.
I figured it out.

In myClass, I have an enum listing the different state values. My
AVAILABLE_STATES variable was placed inside the curly braces for the enum.
This inadvertently placed the AVAILABLE_STATES variable inside the enum and
caused Struts 2 to throw an error message.


DavidZaz wrote:
> 
> I'm trying to access a static constant from a JSP page in Struts 2.0.14,
> but it is not working.
> 
> My JSP page:
> 
> <s:select list="@org.my.company.myClass@AVAILABLE_STATES" />
> 
> Java code:
> 
> package org.my.company;
> 
> import java.util.ArrayList;
> import java.util.List;
> 
> public Class myClass {
> 
> public static final List<String> AVAILABLE_STATES = getStates();
> 
> public static final List<String> getStates() {
> List<String> states = new ArrayList<String>();
> states.add("New York");
> return states;
> }
> 
> When I try to access my jsp page, I receive the following error message:
> 
> Caused by: tag 'select', field 'list': The requested list key
> '@org.my.company.myClass@AVAILABLE_STATES' could not be resolved as a
> collection/array/map/enumeration/iterator type. Example: people or
> people.{name} - [unknown location]
> 
> Does anyone have any suggestion about what needs to be changed?
> 
> Thanks!
> 

-- 
View this message in context: http://old.nabble.com/Accessing-Static-Constants-from-JSP-in-Struts-2.0.14-tp27018870p27019067.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org