Author: dan.j.allen
Date: 2009-05-01 02:32:03 -0400 (Fri, 01 May 2009)
New Revision: 10738
Added:
modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/JcdiManager.java
Modified:
modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/SeamViewHandler.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/TransferStatusMessagesListener.java
Log:
lookup Manager via JNDI rather than EL
Added:
modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/JcdiManager.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/JcdiManager.java
(rev 0)
+++
modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/JcdiManager.java 2009-05-01
06:32:03 UTC (rev 10738)
@@ -0,0 +1,60 @@
+package org.jboss.seam.faces.application;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.inject.manager.Manager;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+/**
+ * <strong>JcdiManager</strong> retrieves the JCDI Manager from JNDI and
caches the
+ * result in an application-scoped attribute.
+ *
+ * @author Dan Allen
+ */
+public class JcdiManager
+{
+ public static final String JCDI_MANAGER_JNDI_NAME = "java:app/Manager";
+
+ public static final String JCDI_MANAGER_ALT_JNDI_NAME =
"java:comp/env/app/Manager";
+
+ private static final String JCDI_MANAGER_CACHE_KEY = JcdiManager.class.getName() +
".CACHE_KEY";
+
+ public static Manager getCurrentManager()
+ {
+ Manager currentManager = null;
+ ExternalContext externalContext =
FacesContext.getCurrentInstance().getExternalContext();
+ if (externalContext != null)
+ {
+ currentManager = (Manager)
externalContext.getApplicationMap().get(JCDI_MANAGER_CACHE_KEY);
+ }
+
+ if (currentManager != null)
+ {
+ return currentManager;
+ }
+
+ try
+ {
+ InitialContext initialContext = new InitialContext();
+ try
+ {
+ currentManager = (Manager) initialContext.lookup(JCDI_MANAGER_JNDI_NAME);
+ }
+ catch (NamingException e)
+ {
+ currentManager = (Manager)
initialContext.lookup(JCDI_MANAGER_ALT_JNDI_NAME);
+ }
+ }
+ catch (NamingException e)
+ {
+ }
+
+ if (currentManager != null && externalContext != null)
+ {
+ externalContext.getApplicationMap().put(JCDI_MANAGER_CACHE_KEY,
currentManager);
+ }
+
+ return currentManager;
+ }
+}
Modified:
modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/SeamViewHandler.java
===================================================================
---
modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/SeamViewHandler.java 2009-05-01
01:17:13 UTC (rev 10737)
+++
modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/SeamViewHandler.java 2009-05-01
06:32:03 UTC (rev 10738)
@@ -6,7 +6,6 @@
import javax.faces.application.ViewHandlerWrapper;
import javax.faces.context.FacesContext;
import org.jboss.seam.faces.lifecycle.TransferStatusMessagesListener;
-import org.jboss.seam.international.StatusMessages;
/**
* Wrap the standard JSF view handler to capture the
@@ -42,6 +41,7 @@
{
// QUESTION hmmm, we have to convert to faces messages now to leverage JSF's
flash feature...I suppose that is okay
new TransferStatusMessagesListener().execute();
+ // should I move this next step into TransferStatusMessagesListener?
if (context.getMessages().hasNext())
{
context.getExternalContext().getFlash().setKeepMessages(true);
Modified:
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/TransferStatusMessagesListener.java
===================================================================
---
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/TransferStatusMessagesListener.java 2009-05-01
01:17:13 UTC (rev 10737)
+++
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/TransferStatusMessagesListener.java 2009-05-01
06:32:03 UTC (rev 10738)
@@ -1,10 +1,8 @@
package org.jboss.seam.faces.lifecycle;
-import java.beans.Introspector;
import javax.faces.event.SystemEvent;
import javax.faces.event.SystemEventListener;
-import org.jboss.seam.el.Expressions;
-import org.jboss.seam.faces.FacesExpressions;
+import org.jboss.seam.faces.application.JcdiManager;
import org.jboss.seam.international.StatusMessages;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
@@ -33,9 +31,8 @@
public void execute()
{
- Expressions expressions = new FacesExpressions();
- // FIXME this is kind of ugly...reminds me of the bad old days of JSF managed
beans
- StatusMessages statusMessages = (StatusMessages)
expressions.createValueExpression(getBeanExpression(StatusMessages.class)).getValue();
+ StatusMessages statusMessages =
JcdiManager.getCurrentManager().getInstanceByType(StatusMessages.class);
+
if (statusMessages != null)
{
statusMessages.onBeforeRender();
@@ -45,14 +42,4 @@
log.warn("Could not locate StatusMessages bean. Status messages will not be
transfered to FacesContext.");
}
}
-
- private String getBeanName(Class beanClass)
- {
- return beanClass.getPackage().getName() + "." +
Introspector.decapitalize(beanClass.getSimpleName());
- }
-
- private String getBeanExpression(Class beanClass)
- {
- return "#{" + getBeanName(beanClass) + "}";
- }
}