Update of /cvsroot/opensymphony/webwork/src/main/webwork/util
In directory sc8-pr-cvs1:/tmp/cvs-serv10926
Modified Files:
ServletValueStack.java
Log Message:
Fixed so that the findInContext method will also search in the session and
application scope when there is no page context. This fixes
Jira issue WW-273
Index: ServletValueStack.java
===================================================================
RCS file: /cvsroot/opensymphony/webwork/src/main/webwork/util/ServletValueStack.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ServletValueStack.java 8 Oct 2002 14:21:50 -0000 1.3
+++ ServletValueStack.java 10 Sep 2003 21:47:11 -0000 1.4
@@ -7,6 +7,9 @@
package webwork.util;
import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
import javax.servlet.jsp.PageContext;
/**
@@ -18,7 +21,6 @@
*/
public class ServletValueStack extends ValueStack
{
-
// Constructor ---------------------------------------------------
public ServletValueStack()
{
@@ -85,7 +87,7 @@
*
* @param context
*/
- private void setContext(PageContext context)
+ public void setContext(PageContext context)
{
this.context = context;
}
@@ -96,12 +98,50 @@
try {
return context.findAttribute(id); // Used in a JSP environment
} catch (Exception e) {
+ // This exception occurred alot before when the page context was not
+ // updated correctly in the stack. I do not know if the comment and
+ // code below is correct and needed anymore, but we keep it for safety
+
//needed for apparent bug in Resin 2.1.1 :(
- return request.getAttribute(id);
+ return findAttribute(id);
}
} else {
- return request.getAttribute(id); // Rarely, if ever, used. Ignore
+ // If the findInContext method is called outside of a jsp page then there
+ // is no page context and this code will execute.
+ return findAttribute(id);
+ }
+ }
+
+ /**
+ * Mimic the behaviour of the findAttribute method in the PageContext
+ * This method is used when there is no pageContext set for this stack
+ * and the findInContext method is called.
+ * Look for the attribute in the request, session and application scope
+ *
+ * @param id
+ * @return found value or null
+ */
+ protected Object findAttribute(String id)
+ {
+ Object result;
+
+ // First look in the request
+ if ((result = request.getAttribute(id)) != null)
+ return result;
+ // If nothing found then look in the session if there is one
+ if (!(request instanceof HttpServletRequest))
+ return null;
+ HttpSession session = ((HttpServletRequest) request).getSession(false);
+ if (session != null)
+ {
+ if ((result = session.getAttribute(id)) != null)
+ return result;
+ // Finally look in the application scope
+ return session.getServletContext().getAttribute(id);
}
+ // We should really look in the application scope here as well,
+ // but we do not have any way of finding it now
+ return null;
}
/**
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.