[jboss-cvs] jboss-seam/src/ui/org/jboss/seam/ui ...
Gavin King
gavin.king at jboss.com
Sat Mar 17 21:31:42 EDT 2007
User: gavin
Date: 07/03/17 21:31:42
Modified: src/ui/org/jboss/seam/ui HtmlLayoutForm.java
HtmlMessageDecoration.java UIDecorate.java
Log:
added explicit support for a message facet
Revision Changes Path
1.8 +137 -9 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.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- HtmlLayoutForm.java 17 Mar 2007 22:09:20 -0000 1.7
+++ HtmlLayoutForm.java 18 Mar 2007 01:31:42 -0000 1.8
@@ -2,6 +2,7 @@
import java.io.IOException;
+import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
@@ -16,7 +17,9 @@
private String labelColumnClass;
private String fieldColumnClass;
private String descriptionColumnClass;
+ private String messageColumnClass;
private String rowClass;
+ private String rowErrorClass;
@Override
public String getFamily()
@@ -57,35 +60,135 @@
return true;
}
- private void renderChild(FacesContext facesContext, UIComponent child) throws IOException
+ private void renderChild(FacesContext context, UIComponent child) throws IOException
{
- ResponseWriter writer = facesContext.getResponseWriter();
+ ResponseWriter writer = context.getResponseWriter();
+ boolean hasMessage = UIDecorate.hasMessage(child, context);
writer.startElement("div", this);
- writer.writeAttribute("class", rowClass, "rowClass");
+ String rowClasses = hasMessage && rowErrorClass!=null ? rowClass + ' ' + rowErrorClass : rowClass;
+ writer.writeAttribute("class", rowClasses, "rowClass");
writer.startElement("span", child);
writer.writeAttribute("class", labelColumnClass, "labelColumnClass");
- renderLabel(facesContext, child);
+ renderLabel(context, child);
writer.endElement("span");
writer.startElement("span", this);
writer.writeAttribute("class", fieldColumnClass, "fieldColumnClass");
- JSF.renderChild(facesContext, child);
+ if (child instanceof EditableValueHolder)
+ {
+ renderField(context, child);
+ }
+ else
+ {
+ JSF.renderChild(context, child);
+ }
+ writer.endElement("span");
+
+ UIComponent message = UIDecorate.getDecoration("message", child);
+ if (message!=null && hasMessage)
+ {
+ message.setParent(child);
+ writer.startElement("span", this);
+ writer.writeAttribute("class", messageColumnClass, "messageColumnClass");
+ JSF.renderChild(context, message);
writer.endElement("span");
+ }
UIComponent description = child.getFacet("description");
if (description != null)
{
writer.startElement("span", this);
writer.writeAttribute("class", descriptionColumnClass, "descriptionColumnClass");
- JSF.renderChild(facesContext, description);
+ JSF.renderChild(context, description);
writer.endElement("span");
}
writer.endElement("div");
}
+ private void renderField(FacesContext context, UIComponent child) throws IOException
+ {
+ boolean hasMessage = UIDecorate.hasMessage(child, context);
+ boolean hasRequired = UIDecorate.hasRequired(child, context);
+
+ UIComponent aroundDecoration = UIDecorate.getDecoration("aroundField", child);
+ UIComponent aroundInvalidDecoration = UIDecorate.getDecoration("aroundInvalidField", child);
+ UIComponent aroundRequiredDecoration = UIDecorate.getDecoration("aroundRequiredField", child);
+ if (aroundDecoration!=null && !hasMessage)
+ {
+ aroundDecoration.setParent(child);
+ aroundDecoration.encodeBegin(context);
+ }
+ if (aroundInvalidDecoration!=null && hasMessage)
+ {
+ aroundInvalidDecoration.setParent(child);
+ aroundInvalidDecoration.encodeBegin(context);
+ }
+ if (aroundRequiredDecoration!=null && hasRequired)
+ {
+ aroundRequiredDecoration.setParent(child);
+ aroundRequiredDecoration.encodeBegin(context);
+ }
+
+ UIComponent beforeDecoration = UIDecorate.getDecoration("beforeField", child);
+ UIComponent beforeInvalidDecoration = UIDecorate.getDecoration("beforeInvalidField", child);
+ UIComponent beforeRequiredDecoration = UIDecorate.getDecoration("beforeRequiredField", child);
+ if ( beforeDecoration!=null && !hasMessage )
+ {
+ beforeDecoration.setParent(child);
+ JSF.renderChild(context, beforeDecoration);
+ }
+ if ( beforeInvalidDecoration!=null && hasMessage )
+ {
+ beforeInvalidDecoration.setParent(child);
+ JSF.renderChild(context, beforeInvalidDecoration);
+ }
+ if ( beforeRequiredDecoration!=null && hasRequired)
+ {
+ beforeRequiredDecoration.setParent(child);
+ JSF.renderChild(context, beforeRequiredDecoration);
+ }
+
+ JSF.renderChild(context, child);
+
+ UIComponent afterDecoration = UIDecorate.getDecoration("afterField", child);
+ UIComponent afterInvalidDecoration = UIDecorate.getDecoration("afterInvalidField", child);
+ UIComponent afterRequiredDecoration = UIDecorate.getDecoration("afterRequiredField", child);
+ if ( afterRequiredDecoration!=null && hasRequired)
+ {
+ afterRequiredDecoration.setParent(child);
+ JSF.renderChild(context, afterRequiredDecoration);
+ }
+ if ( afterDecoration!=null && !hasMessage )
+ {
+ afterDecoration.setParent(child);
+ JSF.renderChild(context, afterDecoration);
+ }
+ if ( afterInvalidDecoration!=null && hasMessage )
+ {
+ afterInvalidDecoration.setParent(child);
+ JSF.renderChild(context, afterInvalidDecoration);
+ }
+
+ if (aroundRequiredDecoration != null && hasRequired)
+ {
+ aroundRequiredDecoration.setParent(child);
+ aroundRequiredDecoration.encodeEnd(context);
+ }
+ if (aroundDecoration!=null && !hasMessage)
+ {
+ aroundDecoration.setParent(child);
+ aroundDecoration.encodeEnd(context);
+ }
+ if (aroundInvalidDecoration!=null && hasMessage)
+ {
+ aroundInvalidDecoration.setParent(child);
+ aroundInvalidDecoration.encodeEnd(context);
+ }
+ }
+
private void renderLabel(FacesContext facesContext, UIComponent child) throws IOException
{
ResponseWriter writer = facesContext.getResponseWriter();
@@ -191,17 +294,23 @@
super.restoreState(context, array[0]);
labelColumnClass = (String) array[1];
fieldColumnClass = (String) array[2];
- rowClass = (String) array[3];
+ descriptionColumnClass = (String) array[3];
+ messageColumnClass = (String) array[4];
+ rowClass = (String) array[5];
+ rowErrorClass = (String) array[6];
}
@Override
public Object saveState(FacesContext context)
{
- Object[] state = new Object[4];
+ Object[] state = new Object[7];
state[0] = super.saveState(context);
state[1] = labelColumnClass;
state[2] = fieldColumnClass;
- state[3] = rowClass;
+ state[3] = descriptionColumnClass;
+ state[4] = messageColumnClass;
+ state[5] = rowClass;
+ state[6] = rowErrorClass;
return state;
}
@@ -245,5 +354,24 @@
this.descriptionColumnClass = descriptionColumnClass;
}
+ public String getMessageColumnClass()
+ {
+ return messageColumnClass;
+ }
+
+ public void setMessageColumnClass(String messageColumnClass)
+ {
+ this.messageColumnClass = messageColumnClass;
+ }
+
+ public String getRowErrorClass()
+ {
+ return rowErrorClass;
+ }
+
+ public void setRowErrorClass(String rowErrorClass)
+ {
+ this.rowErrorClass = rowErrorClass;
+ }
}
1.2 +8 -5 jboss-seam/src/ui/org/jboss/seam/ui/HtmlMessageDecoration.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: HtmlMessageDecoration.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/ui/org/jboss/seam/ui/HtmlMessageDecoration.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- HtmlMessageDecoration.java 2 Oct 2006 18:20:36 -0000 1.1
+++ HtmlMessageDecoration.java 18 Mar 2007 01:31:42 -0000 1.2
@@ -8,11 +8,15 @@
{
public static final String COMPONENT_TYPE = "org.jboss.seam.ui.HtmlMessageDecoration";
- private UIDecorate getParentDecorate(UIComponent component)
+ private String getFor(UIComponent component)
{
if (component instanceof UIDecorate)
{
- return (UIDecorate) component;
+ return UIDecorate.getInputId(component);
+ }
+ else if ( component.getParent() instanceof HtmlLayoutForm )
+ {
+ return UIDecorate.getInputId(component);
}
else if ( component.getParent()==null )
{
@@ -20,15 +24,14 @@
}
else
{
- return getParentDecorate( component.getParent() );
+ return getFor( component.getParent() );
}
}
@Override
public String getFor()
{
- UIDecorate decorate = getParentDecorate(this);
- return decorate==null ? null : decorate.getInputId();
+ return getFor(this);
}
}
1.13 +9 -21 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.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- UIDecorate.java 17 Mar 2007 16:55:12 -0000 1.12
+++ UIDecorate.java 18 Mar 2007 01:31:42 -0000 1.13
@@ -188,15 +188,11 @@
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())
+ if (aroundRequiredDecoration != null && hasRequired())
{
aroundRequiredDecoration.setParent(this);
aroundRequiredDecoration.encodeEnd(facesContext);
}
- }
if (aroundDecoration!=null && !hasMessage)
{
aroundDecoration.setParent(this);
@@ -229,30 +225,22 @@
beforeInvalidDecoration.setParent(this);
JSF.renderChild(facesContext, beforeInvalidDecoration);
}
- if ( beforeRequiredDecoration != null)
- {
- EditableValueHolder evh = (EditableValueHolder) getEditableValueHolder(this);
- if (evh != null && evh.isRequired())
+ if ( beforeRequiredDecoration!=null && hasRequired() )
{
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())
+ if ( afterRequiredDecoration!=null && hasRequired() )
{
afterRequiredDecoration.setParent(this);
JSF.renderChild(facesContext, afterRequiredDecoration);
}
- }
if ( afterDecoration!=null && !hasMessage )
{
afterDecoration.setParent(this);
More information about the jboss-cvs-commits
mailing list