This is an automated email from the ASF dual-hosted git repository.
doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git
The following commit(s) were added to refs/heads/master by this push:
new bd5d0d74 EMPIREDB-404 formGrid componentids and style classes
bd5d0d74 is described below
commit bd5d0d74ade022c0ca371dcdbc311b2e8cadcf8b
Author: Rainer Döbele <[email protected]>
AuthorDate: Sun Mar 19 22:34:47 2023 +0100
EMPIREDB-404
formGrid componentids and style classes
---
.../main/webapp/resources/empire/formGrid.xhtml | 3 +-
.../apache/empire/jsf2/components/ControlTag.java | 42 ++++++++++--------
.../apache/empire/jsf2/components/FormGridTag.java | 14 +++---
.../empire/jsf2/utils/ControlRenderInfo.java | 6 ++-
.../empire/jsf2/utils/TagEncodingHelper.java | 50 ++++++++++++++++++----
5 files changed, 80 insertions(+), 35 deletions(-)
diff --git
a/empire-db-examples/empire-db-example-jsf2/src/main/webapp/resources/empire/formGrid.xhtml
b/empire-db-examples/empire-db-example-jsf2/src/main/webapp/resources/empire/formGrid.xhtml
index 4367bfbe..0c5e262b 100644
---
a/empire-db-examples/empire-db-example-jsf2/src/main/webapp/resources/empire/formGrid.xhtml
+++
b/empire-db-examples/empire-db-example-jsf2/src/main/webapp/resources/empire/formGrid.xhtml
@@ -28,7 +28,8 @@
<cc:attribute name="tag" />
<cc:attribute name="controlTag" />
<cc:attribute name="labelTag" />
- <cc:attribute name="inputTag" />
+ <cc:attribute name="inputTag" />
+ <cc:attribute name="renderAutoId" />
</cc:interface>
<!-- Implementation -->
diff --git
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ControlTag.java
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ControlTag.java
index 66f64490..500c05eb 100644
---
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ControlTag.java
+++
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ControlTag.java
@@ -47,8 +47,9 @@ import org.slf4j.LoggerFactory;
public class ControlTag extends UIInput implements NamingContainer
{
- public static String DEFAULT_LABEL_SEPARATOR_CLASS = "eCtlLabel";
- public static String DEFAULT_INPUT_SEPARATOR_CLASS = "eCtlInput";
+ public static String CONTROL_CLASS = "eControl";
+ public static String LABEL_SEPARATOR_CLASS = "eCtlLabel";
+ public static String INPUT_SEPARATOR_CLASS = "eCtlInput";
/**
* ControlSeparatorComponent
@@ -134,9 +135,9 @@ public class ControlTag extends UIInput implements
NamingContainer
protected void writeAttributes(ResponseWriter writer,
TagEncodingHelper helper)
throws IOException
{
- String styleClass = helper.getTagAttributeString("labelClass",
ControlTag.DEFAULT_LABEL_SEPARATOR_CLASS);
- if (StringUtils.isNotEmpty(styleClass))
- writer.writeAttribute("class", styleClass, null);
+ // style Class
+ String labelClass = helper.getTagAttributeString("labelClass");
+ helper.writeStyleClass(writer, ControlTag.LABEL_SEPARATOR_CLASS,
labelClass);
}
@Override
@@ -162,10 +163,9 @@ public class ControlTag extends UIInput implements
NamingContainer
protected void writeAttributes(ResponseWriter writer,
TagEncodingHelper helper)
throws IOException
{
- String styleClass = helper.getTagAttributeString("inputClass",
ControlTag.DEFAULT_INPUT_SEPARATOR_CLASS);
- // styleClass
- if (StringUtils.isNotEmpty(styleClass))
- writer.writeAttribute("class", styleClass, null);
+ // style Class
+ String inputClass = helper.getTagAttributeString("inputClass");
+ helper.writeStyleClass(writer, ControlTag.INPUT_SEPARATOR_CLASS,
inputClass);
// colspan
String colSpan = helper.getTagAttributeString("colspan");
if (StringUtils.isNotEmpty(colSpan) &&
tagName.equalsIgnoreCase("td"))
@@ -239,7 +239,7 @@ public class ControlTag extends UIInput implements
NamingContainer
protected static final String readOnlyState = "readOnlyState";
- protected final TagEncodingHelper helper =
TagEncodingHelperFactory.create(this, "eInput");
+ protected final TagEncodingHelper helper =
TagEncodingHelperFactory.create(this, CONTROL_CLASS);
protected InputControl control = null;
protected InputControl.InputInfo inpInfo = null;
@@ -331,8 +331,12 @@ public class ControlTag extends UIInput implements
NamingContainer
{ // control wrapper tag
ResponseWriter writer = context.getResponseWriter();
writer.startElement(renderInfo.CONTROL_TAG, this);
- String styleClass = helper.getTagAttributeString("styleClass",
"eControl");
- helper.writeAttribute(writer, InputControl.HTML_ATTR_CLASS,
styleClass);
+ // render id
+ helper.writeComponentId(writer, renderInfo.RENDER_AUTO_ID);
+ // style class
+ String controlClass =
helper.getTagAttributeString("controlClass");
+ String styleClass = helper.getControlContextStyleClass();
+ helper.writeStyleClass(writer, CONTROL_CLASS, controlClass,
styleClass);
}
// LabelSeparatorComponent
@@ -393,15 +397,15 @@ public class ControlTag extends UIInput implements
NamingContainer
ResponseWriter writer = null;
String tagName = renderInfo.INPUT_WRAPPER_TAG;
if (tagName!=null && tagName.length()>0)
- { // attributes
- String inpClass = helper.getTagAttributeString("inputClass",
ControlTag.DEFAULT_INPUT_SEPARATOR_CLASS);
- String colSpan = helper.getTagAttributeString("colspan");
- // render tag
+ { // render tag
writer = context.getResponseWriter();
writer.startElement(tagName, this);
- if (StringUtils.isNotEmpty(inpClass))
- writer.writeAttribute("class", inpClass, null);
- if (StringUtils.isNotEmpty(colSpan) &&
tagName.equalsIgnoreCase("td"))
+ // style Class
+ String inpClass = helper.getTagAttributeString("inputClass");
+ helper.writeStyleClass(writer,
ControlTag.INPUT_SEPARATOR_CLASS, inpClass);
+ // write more
+ String colSpan =
tagName.equalsIgnoreCase(InputControl.HTML_TAG_TD) ?
helper.getTagAttributeString("colspan") : null;
+ if (StringUtils.isNotEmpty(colSpan))
writer.writeAttribute("colspan", colSpan, null);
}
// encode children
diff --git
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/FormGridTag.java
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/FormGridTag.java
index a1e37ea5..e7f8236f 100644
---
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/FormGridTag.java
+++
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/FormGridTag.java
@@ -26,6 +26,7 @@ import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+import org.apache.empire.commons.ObjectUtils;
import org.apache.empire.jsf2.controls.InputControl;
import org.apache.empire.jsf2.utils.ControlRenderInfo;
import org.apache.empire.jsf2.utils.TagEncodingHelper;
@@ -44,8 +45,8 @@ public class FormGridTag extends UIOutput implements
NamingContainer
private enum FormGridMode
{
LEGACY(InputControl.HTML_TAG_DIV, null, InputControl.HTML_TAG_TD,
InputControl.HTML_TAG_TD),
- TABLE ("table", InputControl.HTML_TAG_TR, InputControl.HTML_TAG_TD,
InputControl.HTML_TAG_TD),
- GRID (InputControl.HTML_TAG_DIV, InputControl.HTML_TAG_DIV,
InputControl.HTML_TAG_DIV, InputControl.HTML_TAG_DIV);
+ TABLE (InputControl.HTML_TAG_TABLE, InputControl.HTML_TAG_TR,
InputControl.HTML_TAG_TD, InputControl.HTML_TAG_TD),
+ GRID (InputControl.HTML_TAG_DIV, InputControl.HTML_TAG_DIV,
InputControl.HTML_TAG_DIV, InputControl.HTML_TAG_DIV);
public final String GRID_TAG;
public final String DEFAULT_CONTROL_TAG;
@@ -109,8 +110,10 @@ public class FormGridTag extends UIOutput implements
NamingContainer
// render components
ResponseWriter writer = context.getResponseWriter();
writer.startElement(tagName, this);
- writer.writeAttribute(InputControl.HTML_ATTR_ID, getClientId(), null);
- helper.writeAttribute(writer, InputControl.HTML_ATTR_CLASS,
helper.getTagAttributeString("styleClass", "eFormGrid"));
+ // id
+ helper.writeComponentId(writer, getControlRenderInfo().RENDER_AUTO_ID);
+ // style class
+ helper.writeStyleClass(writer);
helper.writeAttribute(writer, InputControl.HTML_ATTR_STYLE,
helper.getTagAttributeString("style"));
}
@@ -149,8 +152,9 @@ public class FormGridTag extends UIOutput implements
NamingContainer
String controlTag = helper.getTagAttributeString("controlTag",
mode.DEFAULT_CONTROL_TAG);
String labelTag = helper.getTagAttributeString("labelTag",
mode.DEFAULT_LABEL_TAG);
String inputTag = helper.getTagAttributeString("inputTag",
mode.DEFAULT_INPUT_TAG);
+ boolean renderAutoId =
ObjectUtils.getBoolean(helper.getTagAttributeString("renderAutoId"));
// done
- this.controlRenderInfo = new ControlRenderInfo(controlTag, labelTag,
inputTag);
+ this.controlRenderInfo = new ControlRenderInfo(controlTag, labelTag,
inputTag, renderAutoId);
return controlRenderInfo;
}
}
diff --git
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/ControlRenderInfo.java
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/ControlRenderInfo.java
index 9ceffd3c..b6ccaf57 100644
---
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/ControlRenderInfo.java
+++
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/ControlRenderInfo.java
@@ -32,18 +32,20 @@ public class ControlRenderInfo
{
public DefaultControlRenderInfo()
{
- super(null, InputControl.HTML_TAG_TD, InputControl.HTML_TAG_TD);
+ super(null, InputControl.HTML_TAG_TD, InputControl.HTML_TAG_TD,
true);
}
}
public final String CONTROL_TAG;
public final String LABEL_WRAPPER_TAG;
public final String INPUT_WRAPPER_TAG;
+ public final boolean RENDER_AUTO_ID;
- public ControlRenderInfo(String controlTag, String labelTag, String
inputTag)
+ public ControlRenderInfo(String controlTag, String labelTag, String
inputTag, boolean renderAutoId)
{
this.CONTROL_TAG = StringUtils.nullIfEmpty(controlTag);
this.LABEL_WRAPPER_TAG = StringUtils.nullIfEmpty(labelTag);
this.INPUT_WRAPPER_TAG = StringUtils.nullIfEmpty(inputTag);
+ this.RENDER_AUTO_ID = renderAutoId;
}
}
diff --git
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
index 76c5fc57..efc111e4 100644
---
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
+++
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
@@ -1324,13 +1324,6 @@ public class TagEncodingHelper implements NamingContainer
String f = vi.getFormat();
return (f != null && f.indexOf(format) >= 0);
}
-
- public void writeAttribute(ResponseWriter writer, String attribute, Object
value)
- throws IOException
- {
- if (value != null)
- writer.writeAttribute(attribute, value, null);
- }
public String getDisplayText(String text)
{
@@ -1434,6 +1427,47 @@ public class TagEncodingHelper implements NamingContainer
return getTagAttributeString(name, null);
}
+ public String getControlContextStyleClass()
+ {
+ return getContextStyleClass(getTagAttributeString("styleClass"));
+ }
+
+ public void writeAttribute(ResponseWriter writer, String attribute, Object
value)
+ throws IOException
+ {
+ if (value != null)
+ writer.writeAttribute(attribute, value, null);
+ }
+
+ public void writeComponentId(ResponseWriter writer, boolean renderAutoId)
+ throws IOException
+ {
+ // render id
+ if (renderAutoId || !component.getId().startsWith("j_"))
+ writer.writeAttribute(InputControl.HTML_ATTR_ID,
component.getClientId(), null);
+ }
+
+ public void writeStyleClass(ResponseWriter writer, String... styleClasses)
+ throws IOException
+ {
+ String styleClass = null;
+ if (styleClasses.length>2)
+ styleClass = assembleStyleClassString(styleClasses[0], null,
styleClasses[1], styleClasses[2]);
+ else if (styleClasses.length>1)
+ styleClass = assembleStyleClassString(styleClasses[0], null,
styleClasses[1], null);
+ else if (styleClasses.length==1)
+ styleClass = styleClasses[0];
+ if (styleClass != null)
+ writer.writeAttribute(InputControl.HTML_ATTR_CLASS, styleClass,
null);
+ }
+
+ public void writeStyleClass(ResponseWriter writer)
+ throws IOException
+ {
+ String userStyle = getTagAttributeStringEx("styleClass");
+ writeStyleClass(writer, this.cssStyleClass, userStyle);
+ }
+
/* ********************** FormGridTag ********************** */
protected FormGridTag getFormGrid()
@@ -1735,7 +1769,7 @@ public class TagEncodingHelper implements NamingContainer
return getTagStyleClass((String)null);
}
- protected String getContextStyleClass(String addlStyle)
+ public String getContextStyleClass(String addlStyle)
{
String contextStyle = null;
if ((getRecord() instanceof TagContextInfo) && hasColumn())