Author: maschmid
Date: 2012-09-24 10:08:13 -0400 (Mon, 24 Sep 2012)
New Revision: 15164
Added:
branches/community/Seam_2_3/jboss-seam-ui/src/main/java/org/jboss/seam/ui/component/UIDecorateAware.java
Modified:
branches/community/Seam_2_3/jboss-seam-ui/src/main/java/org/jboss/seam/ui/component/UILabel.java
branches/community/Seam_2_3/jboss-seam-ui/src/main/java/org/jboss/seam/ui/component/UIMessage.java
branches/community/Seam_2_3/jboss-seam-ui/src/main/java/org/jboss/seam/ui/renderkit/DecorateRendererBase.java
Log:
JBSEAM-5044, cannot use UIComponent setParent in JSF2, introducing UIDecorateAware
interface which allows the DecorateRendererBase to set the UIDecorate reference directly.
Added:
branches/community/Seam_2_3/jboss-seam-ui/src/main/java/org/jboss/seam/ui/component/UIDecorateAware.java
===================================================================
---
branches/community/Seam_2_3/jboss-seam-ui/src/main/java/org/jboss/seam/ui/component/UIDecorateAware.java
(rev 0)
+++
branches/community/Seam_2_3/jboss-seam-ui/src/main/java/org/jboss/seam/ui/component/UIDecorateAware.java 2012-09-24
14:08:13 UTC (rev 15164)
@@ -0,0 +1,11 @@
+package org.jboss.seam.ui.component;
+
+/**
+ * Component that is aware of being used from a facet by s:decorate
+ */
+public interface UIDecorateAware {
+ /**
+ * Method called by DecorateRendererBase when it's about to render a subtree
containing this component.
+ */
+ void setUIDecorate(UIDecorate decorate);
+}
Modified:
branches/community/Seam_2_3/jboss-seam-ui/src/main/java/org/jboss/seam/ui/component/UILabel.java
===================================================================
---
branches/community/Seam_2_3/jboss-seam-ui/src/main/java/org/jboss/seam/ui/component/UILabel.java 2012-09-21
12:26:22 UTC (rev 15163)
+++
branches/community/Seam_2_3/jboss-seam-ui/src/main/java/org/jboss/seam/ui/component/UILabel.java 2012-09-24
14:08:13 UTC (rev 15164)
@@ -12,8 +12,9 @@
family="javax.faces.Output",
type="org.jboss.seam.ui.Label",generate="org.jboss.seam.ui.component.html.HtmlLabel",
tag = @Tag(baseClass="org.jboss.seam.ui.util.cdk.UIComponentTagBase",
name="label"),
attributes = {"label.xml" })
-public abstract class UILabel extends HtmlOutputLabel
+public abstract class UILabel extends HtmlOutputLabel implements UIDecorateAware
{
+ protected UIDecorate decorate;
/**
* A depth-first search for an EditableValueHolder
@@ -70,7 +71,14 @@
@Override
public String getFor()
{
+ if(decorate != null) {
+ return getFor(decorate);
+ }
return getFor(this);
}
+ @Override
+ public void setUIDecorate(UIDecorate decorate) {
+ this.decorate = decorate;
+ }
}
Modified:
branches/community/Seam_2_3/jboss-seam-ui/src/main/java/org/jboss/seam/ui/component/UIMessage.java
===================================================================
---
branches/community/Seam_2_3/jboss-seam-ui/src/main/java/org/jboss/seam/ui/component/UIMessage.java 2012-09-21
12:26:22 UTC (rev 15163)
+++
branches/community/Seam_2_3/jboss-seam-ui/src/main/java/org/jboss/seam/ui/component/UIMessage.java 2012-09-24
14:08:13 UTC (rev 15164)
@@ -25,7 +25,6 @@
import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlMessage;
-import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.Description;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.Tag;
@@ -38,8 +37,10 @@
family="javax.faces.Message",
type="org.jboss.seam.ui.Message",generate="org.jboss.seam.ui.component.html.HtmlMessage",
tag = @Tag(baseClass="org.jboss.seam.ui.util.cdk.UIComponentTagBase",
name="message"),
attributes = {"message.xml" })
-public abstract class UIMessage extends HtmlMessage {
+public abstract class UIMessage extends HtmlMessage implements UIDecorateAware {
+ protected UIDecorate decorate;
+
/**
* A depth-first search for an EditableValueHolder
*/
@@ -95,7 +96,15 @@
@Override
public String getFor()
{
+ if(decorate != null) {
+ return getFor(decorate);
+ }
+
return getFor(this);
}
-
+
+ @Override
+ public void setUIDecorate(UIDecorate decorate) {
+ this.decorate = decorate;
+ }
}
Modified:
branches/community/Seam_2_3/jboss-seam-ui/src/main/java/org/jboss/seam/ui/renderkit/DecorateRendererBase.java
===================================================================
---
branches/community/Seam_2_3/jboss-seam-ui/src/main/java/org/jboss/seam/ui/renderkit/DecorateRendererBase.java 2012-09-21
12:26:22 UTC (rev 15163)
+++
branches/community/Seam_2_3/jboss-seam-ui/src/main/java/org/jboss/seam/ui/renderkit/DecorateRendererBase.java 2012-09-24
14:08:13 UTC (rev 15164)
@@ -11,6 +11,7 @@
import org.jboss.seam.contexts.Context;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.ui.component.UIDecorate;
+import org.jboss.seam.ui.component.UIDecorateAware;
import org.jboss.seam.ui.util.Decoration;
import org.jboss.seam.ui.util.HTML;
import org.jboss.seam.ui.util.cdk.RendererBase;
@@ -22,7 +23,7 @@
// Place the attributes you want to store away
private Map<String, Object> originalValues = new HashMap();
// The list of attributes in the event scope to store away
- String[] storeOriginals = new String[] {"invalid", "required"};
+ String[] storeOriginals = new String[] {"invalid", "required"};
@Override
protected Class getComponentClass()
@@ -30,6 +31,21 @@
return UIDecorate.class;
}
+ private static void setUIDecorate(UIComponent component, UIDecorate decorator)
+ {
+ if (component instanceof UIDecorateAware)
+ {
+ ((UIDecorateAware)component).setUIDecorate(decorator);
+ }
+ for (Object child: component.getChildren())
+ {
+ if (child instanceof UIComponent)
+ {
+ setUIDecorate((UIComponent)child, decorator);
+ }
+ }
+ }
+
/**
* Store away the attribute from the event context (if it is set)
*
@@ -95,12 +111,12 @@
UIComponent aroundInvalidDecoration =
decorate.getDecoration("aroundInvalidField");
if (aroundDecoration != null && !hasMessage)
{
- aroundDecoration.setParent(decorate);
+ setUIDecorate(aroundDecoration, decorate);
aroundDecoration.encodeBegin(context);
}
if (aroundInvalidDecoration != null && hasMessage)
{
- aroundInvalidDecoration.setParent(decorate);
+ setUIDecorate(aroundInvalidDecoration, decorate);
aroundInvalidDecoration.encodeBegin(context);
}
}
@@ -115,12 +131,12 @@
UIComponent aroundInvalidDecoration =
decorate.getDecoration("aroundInvalidField");
if (aroundDecoration != null && !hasMessage)
{
- aroundDecoration.setParent(decorate);
+ setUIDecorate(aroundDecoration, decorate);
aroundDecoration.encodeEnd(context);
}
if (aroundInvalidDecoration != null && hasMessage)
{
- aroundInvalidDecoration.setParent(decorate);
+ setUIDecorate(aroundInvalidDecoration, decorate);
aroundInvalidDecoration.encodeEnd(context);
}
if (decorate.isEnclose())
@@ -142,12 +158,12 @@
UIComponent beforeInvalidDecoration =
decorate.getDecoration("beforeInvalidField");
if (beforeDecoration != null && !hasMessage)
{
- beforeDecoration.setParent(decorate);
+ setUIDecorate(beforeDecoration, decorate);
renderChild(context, beforeDecoration);
}
if (beforeInvalidDecoration != null && hasMessage)
{
- beforeInvalidDecoration.setParent(decorate);
+ setUIDecorate(beforeInvalidDecoration, decorate);
renderChild(context, beforeInvalidDecoration);
}
@@ -157,12 +173,12 @@
UIComponent afterInvalidDecoration =
decorate.getDecoration("afterInvalidField");
if (afterDecoration != null && !hasMessage)
{
- afterDecoration.setParent(decorate);
+ setUIDecorate(afterDecoration, decorate);
renderChild(context, afterDecoration);
}
if (afterInvalidDecoration != null && hasMessage)
{
- afterInvalidDecoration.setParent(decorate);
+ setUIDecorate(afterInvalidDecoration, decorate);
renderChild(context, afterInvalidDecoration);
}
}
@@ -172,4 +188,4 @@
{
return true;
}
-}
\ No newline at end of file
+}