struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From phillips1021 <>
Subject Using Expression Language (EL) To Access ActionSupport Class Properties
Date Mon, 04 May 2009 18:00:36 GMT

We are building a new web application that uses both JSecurity
(, now known as Ki) and
Struts 2 (version 2.1.6).  

In many of the JSPs for this application, we need to provide a dynamic
String value to the JSecurity tag library's hasAnyRoles tag.  This tag's
format is:

<jsec:hasAnyRoles name="Staff,Admin">
...content to include if current user has one of the roles specified in the
name attribute...

Of course instead of hard-coding the values for the name attribute we want
to have the the attribute's value rendered dynamically using Struts 2.  

First we tried using:

<jsec:hasAnyRoles name="<s:property value='roles' />" ></jsec:hasAnyRoles>

But that did not work even though we have a public method named getRoles in
the action support class that renders this jsp page.

So just for a test we tried using expression language (EL):

<jsec:hasAnyRoles name="${roles}" ></jsec:hasAnyRoles>

And the above worked just fine.  

I didn't know you could access properties of the ActionSupport class using
Expression Language. 

I researched the ability to use Expression Language (EL) to access
properties of the ActionSupport class in the Struts 2 documentation at and in this mailing list.  I didn't find much about
the capability to use EL to access properties of the ActionSupport class. 
The documentation clearly states NOT to use EL in attributes for Struts 2
tags, but it's not clear on using EL to access ActionSupport class
properties outside of the Struts 2 tags.

Since we are building a new web application that will be around for some
time and would like to be able to upgrade to future versions of Struts 2,
we'd like to know if the ability to access ActionSupport class properties
using EL is a built-in and a supported feature of Struts 2?  

Below is some test code to detail how this works:

ActionSupport class:

import com.opensymphony.xwork2.ActionSupport;

public class TestActionSupport extends ActionSupport {

	private static final long serialVersionUID = 1L;

	public String execute() throws Exception {

		return SUCCESS;

	public String getRoles() {
		return "Staff,Admin";



JSP View rendered when above class returns SUCCESS:

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <title>Test of Struts 2 and EL</title>

    <h3>Test of Struts 2 and EL Results Page</h3>
    <p>Roles via expression language: ${roles}</p>
    <p>Roles via Struts 2 property tag: <s:property value='roles' /></p>

Does Struts 2 turn the ActionSupport class itself turned into a bean object
that is placed in request scope?  Is that how the Expression Language
${roles} is able to execute correctly?

Thanks for any information provided that helps us understand the use of EL
to access the ActionSupport class properties.


View this message in context:
Sent from the Struts - User mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message