[jboss-cvs] jboss-seam/src/ui/org/jboss/seam/ui ...
Peter Muir
peter at bleepbleep.org.uk
Thu Mar 15 20:47:18 EDT 2007
User: pmuir
Date: 07/03/15 20:47:18
Modified: src/ui/org/jboss/seam/ui UIDecorate.java
HtmlLayoutForm.java
Log:
add xxxRequiredField facets to s:decorate, and add xxxXXXLabel facets to s:layoutForm
Revision Changes Path
1.10 +133 -59 jboss-seam/src/ui/org/jboss/seam/ui/UIDecorate.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UIDecorate.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/ui/org/jboss/seam/ui/UIDecorate.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- UIDecorate.java 15 Mar 2007 12:28:28 -0000 1.9
+++ UIDecorate.java 16 Mar 2007 00:47:18 -0000 1.10
@@ -15,76 +15,121 @@
private String forId;
- @Override
- public String getFamily()
+ protected static UIComponent getDecoration(String name, UIComponent component)
{
- return COMPONENT_FAMILY;
+ UIComponent dec = component.getFacet(name);
+ if (dec!=null) return dec;
+ if ( component.getParent()==null ) return null;
+ return getDecoration( name, component.getParent() );
}
- private boolean hasMessage()
+ /**
+ * A depth-first search for an EditableValueHolder
+ */
+ protected static UIComponent getEditableValueHolder(UIComponent component)
{
- String clientId = getInputClientId();
- if (clientId==null)
+ for (Object child: component.getChildren())
{
- return false;
+ if (child instanceof EditableValueHolder)
+ {
+ UIComponent evh =(UIComponent) child;
+ if ( evh.isRendered() )
+ {
+ return evh;
}
- else
+ }
+ else if (child instanceof UIComponent)
{
- return getFacesContext().getMessages(clientId).hasNext();
+ UIComponent evh = getEditableValueHolder( (UIComponent) child );
+ if (evh!=null) return evh;
+ }
}
+ return null;
}
- public String getInputId()
+ protected static String getInputId(String forId, UIComponent cmp)
{
- String id = getFor();
- if (id==null)
+ if (forId==null)
{
- UIComponent evh = getEditableValueHolder(this);
+ UIComponent evh = getEditableValueHolder(cmp);
return evh==null ? null : evh.getId();
}
else
{
- return id;
+ return forId;
+ }
}
+
+ protected static String getInputClientId(String forId, UIComponent cmp, FacesContext facesContext)
+ {
+ UIComponent input = getInput(forId, cmp, facesContext);
+ return input == null ? null : input.getClientId(facesContext);
}
- private String getInputClientId()
+ protected static UIComponent getInput(String forId, UIComponent cmp, FacesContext facesContext)
{
- String id = getFor();
- if (id==null)
+ if (forId==null)
{
- UIComponent evh = getEditableValueHolder(this);
- return evh==null ? null : evh.getClientId( getFacesContext() );
+ UIComponent evh = getEditableValueHolder(cmp);
+ return evh==null ? null : evh;
}
else
{
- UIComponent component = findComponent(id);
- return component==null ? null : component.getClientId( getFacesContext() );
+ UIComponent component = cmp.findComponent(forId);
+ return component==null ? null : component;
}
}
- /**
- * A depth-first search for an EditableValueHolder
- */
- protected static UIComponent getEditableValueHolder(UIComponent component)
+ protected static boolean hasMessage(String forId, UIComponent cmp, FacesContext facesContext)
{
- for (Object child: component.getChildren())
+ String clientId = getInputClientId(forId, cmp, facesContext);
+ if (clientId==null)
{
- if (child instanceof EditableValueHolder)
+ return false;
+ }
+ else
{
- UIComponent evh =(UIComponent) child;
- if ( evh.isRendered() )
+ return facesContext.getMessages(clientId).hasNext();
+ }
+ }
+
+ protected static boolean hasRequired(String forId, UIComponent cmp, FacesContext facesContext)
{
- return evh;
+ EditableValueHolder evh = (EditableValueHolder) getInput(forId, cmp, facesContext);
+ if (evh == null)
+ {
+ return false;
}
+ else
+ {
+ return evh.isRequired();
}
- else if (child instanceof UIComponent)
+ }
+
+ @Override
+ public String getFamily()
{
- UIComponent evh = getEditableValueHolder( (UIComponent) child );
- if (evh!=null) return evh;
+ return COMPONENT_FAMILY;
}
+
+ protected boolean hasMessage()
+ {
+ return hasMessage(getFor(), this, getFacesContext());
}
- return null;
+
+ protected boolean hasRequired()
+ {
+ return hasRequired(getFor(), this, getFacesContext());
+ }
+
+ public String getInputId()
+ {
+ return getInputId(getFor(), this);
+ }
+
+ protected UIComponent getInput()
+ {
+ return getInput(getFor(), this, getFacesContext());
}
@Override
@@ -103,19 +148,11 @@
this.forId = forId;
}
- private UIComponent getDecoration(String name)
+ protected UIComponent getDecoration(String name)
{
return getDecoration(name, this);
}
- private static UIComponent getDecoration(String name, UIComponent component)
- {
- UIComponent dec = component.getFacet(name);
- if (dec!=null) return dec;
- if ( component.getParent()==null ) return null;
- return getDecoration( name, component.getParent() );
- }
-
@Override
public void encodeBegin(FacesContext context) throws IOException
{
@@ -123,8 +160,10 @@
context.getResponseWriter().startElement("span", this);
context.getResponseWriter().writeAttribute("id", getClientId(context), "id");
boolean hasMessage = hasMessage();
+
UIComponent aroundDecoration = getDecoration("aroundField");
UIComponent aroundInvalidDecoration = getDecoration("aroundInvalidField");
+ UIComponent aroundRequiredDecoration = getDecoration("aroundRequiredField");
if (aroundDecoration!=null && !hasMessage)
{
aroundDecoration.setParent(this);
@@ -135,26 +174,41 @@
aroundInvalidDecoration.setParent(this);
aroundInvalidDecoration.encodeBegin(context);
}
+ if (aroundRequiredDecoration != null && hasRequired())
+ {
+ aroundRequiredDecoration.setParent(this);
+ aroundRequiredDecoration.encodeBegin(context);
+ }
}
@Override
- public void encodeEnd(FacesContext context) throws IOException
+ public void encodeEnd(FacesContext facesContext) throws IOException
{
boolean hasMessage = hasMessage();
UIComponent aroundDecoration = getDecoration("aroundField");
UIComponent aroundInvalidDecoration = getDecoration("aroundInvalidField");
+ UIComponent aroundRequiredDecoration = getDecoration("aroundRequiredField");
+ if (aroundRequiredDecoration != null)
+ {
+ EditableValueHolder evh = (EditableValueHolder) getEditableValueHolder(this);
+ if (evh != null && evh.isRequired())
+ {
+ aroundRequiredDecoration.setParent(this);
+ aroundRequiredDecoration.encodeEnd(facesContext);
+ }
+ }
if (aroundDecoration!=null && !hasMessage)
{
aroundDecoration.setParent(this);
- aroundDecoration.encodeEnd(context);
+ aroundDecoration.encodeEnd(facesContext);
}
if (aroundInvalidDecoration!=null && hasMessage)
{
aroundInvalidDecoration.setParent(this);
- aroundInvalidDecoration.encodeEnd(context);
+ aroundInvalidDecoration.encodeEnd(facesContext);
}
- context.getResponseWriter().endElement("span");
- super.encodeEnd(context);
+ facesContext.getResponseWriter().endElement("span");
+ super.encodeEnd(facesContext);
}
@Override
@@ -164,6 +218,7 @@
UIComponent beforeDecoration = getDecoration("beforeField");
UIComponent beforeInvalidDecoration = getDecoration("beforeInvalidField");
+ UIComponent beforeRequiredDecoration = getDecoration("beforeRequiredField");
if ( beforeDecoration!=null && !hasMessage )
{
beforeDecoration.setParent(this);
@@ -174,11 +229,30 @@
beforeInvalidDecoration.setParent(this);
JSF.renderChild(facesContext, beforeInvalidDecoration);
}
+ if ( beforeRequiredDecoration != null)
+ {
+ EditableValueHolder evh = (EditableValueHolder) getEditableValueHolder(this);
+ if (evh != null && evh.isRequired())
+ {
+ beforeRequiredDecoration.setParent(this);
+ JSF.renderChild(facesContext, beforeRequiredDecoration);
+ }
+ }
JSF.renderChildren(facesContext, this);
UIComponent afterDecoration = getDecoration("afterField");
UIComponent afterInvalidDecoration = getDecoration("afterInvalidField");
+ UIComponent afterRequiredDecoration = getDecoration("afterRequiredDecoration");
+ if ( afterRequiredDecoration != null)
+ {
+ EditableValueHolder evh = (EditableValueHolder) getEditableValueHolder(this);
+ if (evh != null && evh.isRequired())
+ {
+ afterRequiredDecoration.setParent(this);
+ JSF.renderChild(facesContext, afterRequiredDecoration);
+ }
+ }
if ( afterDecoration!=null && !hasMessage )
{
afterDecoration.setParent(this);
1.2 +144 -59 jboss-seam/src/ui/org/jboss/seam/ui/HtmlLayoutForm.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: HtmlLayoutForm.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/ui/org/jboss/seam/ui/HtmlLayoutForm.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- HtmlLayoutForm.java 15 Mar 2007 12:28:28 -0000 1.1
+++ HtmlLayoutForm.java 16 Mar 2007 00:47:18 -0000 1.2
@@ -2,11 +2,11 @@
import java.io.IOException;
-import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+
public class HtmlLayoutForm extends UIStyleDecoration
{
@@ -24,20 +24,11 @@
for (Object child : this.getChildren())
{
- if (child instanceof UIDecorate)
+ if (child instanceof UIComponent)
{
- UIDecorate decorate = (UIDecorate) child;
- // Get the label facet
- UIComponent label = decorate.getFacet("label");
- UIComponent belowField = decorate.getFacet("belowField");
- UIComponent belowLabel = decorate.getFacet("belowLabel");
- EditableValueHolder evh = (EditableValueHolder) UIDecorate.getEditableValueHolder(decorate);
- writeRow(context, decorate, label, belowField, belowLabel, evh);
- }
- else if (child instanceof UIComponent)
- {
- writeRow(context, (UIComponent) child, null, null, null, null);
+ writeRow(context, (UIComponent) child);
}
+
}
}
@@ -47,40 +38,26 @@
return true;
}
- private void writeRow(FacesContext context, UIComponent child, UIComponent label, UIComponent belowField, UIComponent belowLabel, EditableValueHolder evh) throws IOException
+ private void writeRow(FacesContext facesContext, UIComponent child) throws IOException
{
- ResponseWriter writer = context.getResponseWriter();
- writer.startElement(HTML.TR_ELEM, this);
- if (label == null)
+ UIComponent belowField = child.getFacet("belowField");
+ UIComponent belowLabel = child.getFacet("belowLabel");
+
+ ResponseWriter writer = facesContext.getResponseWriter();
+
+
+
+ if (child instanceof UIDecorate)
{
+ writer.startElement(HTML.TR_ELEM, child);
writer.startElement(HTML.TD_ELEM, child);
- writer.writeAttribute(HTML.COLSPAN_ATTR, "2", HTML.COLSPAN_ATTR);
- JSF.renderChild(context, child);
- writer.endElement(HTML.TD_ELEM);
- }
- else
- {
- writer.startElement(HTML.TD_ELEM, label);
- writer.writeAttribute(HTML.ALIGN_ATTR, "right", HTML.ALIGN_ATTR);
- writer.startElement(HTML.LABEL_ELEM, label);
- if (evh != null)
- {
- writer.writeAttribute(HTML.FOR_ATTR, ((UIComponent) evh).getClientId(context), HTML.FOR_ATTR);
- if (evh.isRequired())
- {
- writer.startElement(HTML.SPAN_ELEM, label);
- writer.writeAttribute(HTML.CLASS_ATTR, "required", HTML.CLASS_ATTR);
- writer.write("∗");
- writer.endElement(HTML.SPAN_ELEM);
- }
- }
- JSF.renderChild(context, label);
- writer.endElement(HTML.LABEL_ELEM);
+
+ writeLabel(facesContext, (UIDecorate) child);
+
writer.endElement(HTML.TD_ELEM);
writer.startElement(HTML.TD_ELEM, child);
- JSF.renderChild(context, child);
+ JSF.renderChild(facesContext, child);
writer.endElement(HTML.TD_ELEM);
- }
writer.endElement(HTML.TR_ELEM);
if (belowLabel != null || belowField != null)
{
@@ -88,7 +65,7 @@
if (belowLabel != null)
{
writer.startElement(HTML.TD_ELEM, belowLabel);
- JSF.renderChild(context, belowLabel);
+ JSF.renderChild(facesContext, belowLabel);
writer.endElement(HTML.TD_ELEM);
}
else
@@ -99,7 +76,7 @@
if (belowField != null)
{
writer.startElement(HTML.TD_ELEM, belowField);
- JSF.renderChild(context, belowField);
+ JSF.renderChild(facesContext, belowField);
writer.endElement(HTML.TD_ELEM);
}
else
@@ -109,6 +86,114 @@
}
writer.endElement(HTML.TR_ELEM);
}
+ }
+ else
+ {
+ writer.startElement(HTML.TR_ELEM, this);
+ writer.startElement(HTML.TD_ELEM, child);
+ writer.writeAttribute(HTML.COLSPAN_ATTR, "2", HTML.COLSPAN_ATTR);
+ JSF.renderChild(facesContext, child);
+ writer.endElement(HTML.TD_ELEM);
+ writer.endElement(HTML.TR_ELEM);
+ if (belowField != null)
+ {
+ writer.startElement(HTML.TD_ELEM, belowField);
+ writer.writeAttribute(HTML.COLSPAN_ATTR, "2", HTML.COLSPAN_ATTR);
+ JSF.renderChild(facesContext, belowField);
+ writer.endElement(HTML.TD_ELEM);
+ }
+ }
+ }
+
+ private void writeLabel(FacesContext facesContext, UIDecorate child) throws IOException
+ {
+ ResponseWriter writer = facesContext.getResponseWriter();
+
+ // Write out a label element
+ UIComponent label = child.getFacet("label");
+ if (label != null)
+ {
+ writer.startElement(HTML.LABEL_ELEM, label);
+ writer.writeAttribute(HTML.FOR_ATTR, child.getInput().getClientId(facesContext), HTML.FOR_ATTR);
+
+ boolean hasMessage = child.hasMessage();
+ boolean hasRequired = child.hasRequired();
+
+ UIComponent aroundLabelDecoration = child.getDecoration("aroundLabel");
+ UIComponent aroundInvalidLabelDecoration = child.getDecoration("aroundInvalidLabel");
+ UIComponent aroundRequiredLabelDecoration = child.getDecoration("aroundRequiredLabel");
+ if (aroundLabelDecoration != null && !hasMessage)
+ {
+ aroundLabelDecoration.setParent(child);
+ aroundLabelDecoration.encodeBegin(facesContext);
+ }
+ if (aroundInvalidLabelDecoration != null && hasMessage)
+ {
+ aroundInvalidLabelDecoration.setParent(child);
+ aroundInvalidLabelDecoration.encodeBegin(facesContext);
+ }
+ if (aroundRequiredLabelDecoration != null && hasRequired)
+ {
+ aroundRequiredLabelDecoration.setParent(child);
+ aroundRequiredLabelDecoration.encodeBegin(facesContext);
+ }
+
+ UIComponent beforeLabelDecoration = child.getDecoration("beforeLabel");
+ UIComponent beforeInvalidLabelDecoration = child.getDecoration("beforeInvalidLabel");
+ UIComponent beforeRequiredLabelDecoration = child.getDecoration("beforeRequiredLabel");
+ if (beforeLabelDecoration != null && !hasMessage)
+ {
+ beforeLabelDecoration.setParent(child);
+ JSF.renderChild(facesContext, beforeLabelDecoration);
+ }
+ if (beforeInvalidLabelDecoration != null && hasMessage)
+ {
+ beforeInvalidLabelDecoration.setParent(child);
+ JSF.renderChild(facesContext, beforeInvalidLabelDecoration);
+ }
+ if (beforeRequiredLabelDecoration != null && hasRequired)
+ {
+ beforeRequiredLabelDecoration.setParent(child);
+ JSF.renderChild(facesContext, beforeRequiredLabelDecoration);
+ }
+
+ JSF.renderChild(facesContext, label);
+
+ UIComponent afterLabelDecoration = UIDecorate.getDecoration("afterLabel", child);
+ UIComponent afterInvalidLabelDecoration = UIDecorate.getDecoration("afterInvalidLabel", child);
+ UIComponent afterRequiredLabelDecoration = UIDecorate.getDecoration("afterRequiredLabel", child);
+ if (afterRequiredLabelDecoration != null && hasRequired)
+ {
+ afterRequiredLabelDecoration.setParent(child);
+ JSF.renderChild(facesContext, afterRequiredLabelDecoration);
+ }
+ if (afterLabelDecoration != null && !hasMessage)
+ {
+ afterLabelDecoration.setParent(child);
+ JSF.renderChild(facesContext, afterLabelDecoration);
+ }
+ if (afterInvalidLabelDecoration != null && hasMessage)
+ {
+ afterInvalidLabelDecoration.setParent(child);
+ JSF.renderChild(facesContext, afterInvalidLabelDecoration);
+ }
+
+ if (aroundRequiredLabelDecoration != null && hasRequired)
+ {
+ aroundRequiredLabelDecoration.setParent(child);
+ aroundRequiredLabelDecoration.encodeEnd(facesContext);
+ }
+ if (aroundLabelDecoration != null && !hasMessage)
+ {
+ aroundLabelDecoration.setParent(child);
+ aroundLabelDecoration.encodeEnd(facesContext);
+ }
+ if (aroundInvalidLabelDecoration != null && hasMessage)
+ {
+ aroundInvalidLabelDecoration.setParent(child);
+ aroundInvalidLabelDecoration.encodeEnd(facesContext);
+ }
+ }
}
More information about the jboss-cvs-commits
mailing list