r6874 - in dumbhippo/trunk/server/src/com/dumbhippo/web: . tags



Author: marinaz
Date: 2007-11-06 18:45:26 -0600 (Tue, 06 Nov 2007)
New Revision: 6874

Added:
   dumbhippo/trunk/server/src/com/dumbhippo/web/Context.java
Modified:
   dumbhippo/trunk/server/src/com/dumbhippo/web/tags/BeanTag.java
Log:
Add @Context annotation that allows accessing full page context from the pages that back jsps.

Added: dumbhippo/trunk/server/src/com/dumbhippo/web/Context.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/web/Context.java	2007-11-06 17:05:07 UTC (rev 6873)
+++ dumbhippo/trunk/server/src/com/dumbhippo/web/Context.java	2007-11-07 00:45:26 UTC (rev 6874)
@@ -0,0 +1,16 @@
+package com.dumbhippo.web;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * If this annotation is set on a field of a class instantiated with
+ * <dh:bean> then the field will be filled in with the full page context.
+ *
+ */
+ Retention(RetentionPolicy.RUNTIME)
+ Target({ElementType.FIELD})
+public @interface Context {
+}
\ No newline at end of file

Modified: dumbhippo/trunk/server/src/com/dumbhippo/web/tags/BeanTag.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/web/tags/BeanTag.java	2007-11-06 17:05:07 UTC (rev 6873)
+++ dumbhippo/trunk/server/src/com/dumbhippo/web/tags/BeanTag.java	2007-11-07 00:45:26 UTC (rev 6874)
@@ -17,6 +17,7 @@
 import com.dumbhippo.web.Download;
 import com.dumbhippo.web.DownloadBean;
 import com.dumbhippo.web.FromJspContext;
+import com.dumbhippo.web.Context;
 import com.dumbhippo.web.PagePositions;
 import com.dumbhippo.web.PagePositionsBean;
 import com.dumbhippo.web.Scope;
@@ -136,7 +137,10 @@
 			throw new RuntimeException("Can't instantiate " + clazz.getName(), e);
 		}
 		
-		for (Class<?> c = clazz; c.getPackage() == clazz.getPackage(); c = c.getSuperclass()) {
+		/* This are already too many types of injections. Do not add anything more here; 
+		 * replace everything but FromJspContext with a single @Inject annotation;
+		 * there is an example in DMClassHolder.java */
+		for (Class<?> c = clazz; c.getPackage() == clazz.getPackage(); c = c.getSuperclass()) {			
 			for (Field f : c.getDeclaredFields()) {
 				if (f.isAnnotationPresent(Signin.class)) {
 					// if the field is UserSigninBean or subclass, then
@@ -156,6 +160,8 @@
 				} else if (f.isAnnotationPresent(PagePositions.class) &&
 						f.getType().isAssignableFrom(PagePositionsBean.class)) {
 						setField(o, f, getPagePositionsBean());
+				} else if (f.isAnnotationPresent(Context.class)) {
+						setField(o, f, (PageContext)getJspContext());						
 				} else if (f.isAnnotationPresent(FromJspContext.class)) {
 					FromJspContext a = f.getAnnotation(FromJspContext.class);
 					String key = a.value();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]