Friend of mine threw together this filter that exposes methods on the
ValueStack (hence your action) to the JSTL expression language. Now I can
finally do a:

<c:out value="${name}"/>

and have it hit the getName() method in my action. Very cool.

Just take the class below and add it as a filter. Use filter mapping of
*.action, or whatever your WebWork servlet is mapped to.

<filter-mapping>
    <filter-name>JSTLFilter</filter-name>
    <servlet-name>action</servlet-name>
</filter-mapping>

jim



import webwork.util.ValueStack;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;

public class JSTLFilter implements javax.servlet.Filter {

        FilterConfig _filterConfig;

        public FilterConfig getFilterConfig() {
                return _filterConfig;
        }

        public void setFilterConfig(FilterConfig filterConfig) {
                _filterConfig = filterConfig;
        }

        public void init(FilterConfig filterConfig) throws ServletException {
        }

        public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
                        throws IOException, ServletException {
                // Make sure it is an HttpServletRequest, if so, create the wrapper and
pass it on
                if (request instanceof HttpServletRequest) {
                        ServletRequest wrappedRequest = new
JSTLRequestWrapper((HttpServletRequest)request);
                        chain.doFilter(wrappedRequest, response);
                } else {
                // Otherwise, just pass the request on down the chain
                        chain.doFilter(request, response);
                }
        }

        public void destroy() {

        }
}



class JSTLRequestWrapper extends HttpServletRequestWrapper{
        private ServletRequest wrappedRequest;

        public JSTLRequestWrapper(HttpServletRequest request) {
                super(request);
                wrappedRequest = request;
        }

        public Object getAttribute(String s) {
                Object attr = super.getAttribute(s);
                if (null != attr) {
                        return attr;
                } else {
                        // If not found, then try the ValueStack
                        ValueStack stack = ValueStack.getStack(wrappedRequest);
                        if (null == stack) return null;
                        else return stack.findValue(s);
                }
        }
}



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Opensymphony-webwork mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork

Reply via email to