[seam-commits] Seam SVN: r9436 - branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/java/org/jboss/seam/ui/renderkit.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Mon Oct 27 10:26:15 EDT 2008
Author: manaRH
Date: 2008-10-27 10:26:15 -0400 (Mon, 27 Oct 2008)
New Revision: 9436
Modified:
branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/java/org/jboss/seam/ui/renderkit/DecorateRendererBase.java
Log:
JBPAPP-1298
Modified: branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/java/org/jboss/seam/ui/renderkit/DecorateRendererBase.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/java/org/jboss/seam/ui/renderkit/DecorateRendererBase.java 2008-10-27 13:58:40 UTC (rev 9435)
+++ branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/java/org/jboss/seam/ui/renderkit/DecorateRendererBase.java 2008-10-27 14:26:15 UTC (rev 9436)
@@ -1,11 +1,14 @@
package org.jboss.seam.ui.renderkit;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+import org.jboss.seam.contexts.Context;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.ui.component.UIDecorate;
import org.jboss.seam.ui.util.Decoration;
@@ -14,18 +17,58 @@
public class DecorateRendererBase extends RendererBase
{
-
+ // Place the attributes you want to store away
+ private Map<String, Object> originalValues = new HashMap<String, Object>();
+ // The list of attributes in the event scope to store away
+ String[] storeOriginals = new String[] {"invalid", "required"};
+
@Override
protected Class getComponentClass()
{
return UIDecorate.class;
}
+ /**
+ * Store away the attribute from the event context (if it is set)
+ *
+ * @param names The list of context keys to store away
+ * @param context The context to target
+ */
+ private void storeOriginalValues(String[] names, Context context)
+ {
+ for (String name : names)
+ {
+ if (context.isSet(name))
+ {
+ originalValues.put(name, context.get(name));
+ }
+ }
+ }
+
+ /**
+ * Restores the state of the event context. If the value is stored away, it is restored
+ * It it was not in the map, it was not in the context in the first place so clean
+ * up what we have placed there during this run.
+ *
+ * @param names The list of context keys to restore
+ */
+ private void restoreOriginalValues(String[] names, Context context) {
+ for (String name : names) {
+ if (originalValues.containsKey(name)) {
+ context.set(name, originalValues.get(name));
+ } else {
+ context.remove(name);
+ }
+ }
+ }
+
@Override
protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent component) throws IOException
{
UIDecorate decorate = (UIDecorate) component;
+ storeOriginalValues(storeOriginals, Contexts.getEventContext());
+
Contexts.getEventContext().set("invalid", Decoration.hasMessage(decorate, context));
Contexts.getEventContext().set("required", Decoration.hasRequired(component, context));
@@ -76,8 +119,7 @@
}
context.getResponseWriter().endElement("div");
- Contexts.getEventContext().remove("invalid");
- Contexts.getEventContext().remove("required");
+ restoreOriginalValues(storeOriginals, Contexts.getEventContext());
}
@Override
More information about the seam-commits
mailing list