Author: Alex.Kolonitsky
Date: 2009-02-09 09:23:17 -0500 (Mon, 09 Feb 2009)
New Revision: 12602
Modified:
trunk/samples/toolBarDemo/src/main/webapp/pages/index.jsp
trunk/ui/dataTable/src/main/java/org/richfaces/component/UIColumnGroup.java
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
trunk/ui/toolBar/src/main/java/org/richfaces/component/UIToolBarGroup.java
trunk/ui/toolBar/src/main/java/org/richfaces/renderkit/html/ToolBarGroupRenderer.java
Log:
ToolBar group: unnesessary separators appears
https://jira.jboss.org/jira/browse/RF-1825
Modified: trunk/samples/toolBarDemo/src/main/webapp/pages/index.jsp
===================================================================
--- trunk/samples/toolBarDemo/src/main/webapp/pages/index.jsp 2009-02-09 10:53:41 UTC (rev
12601)
+++ trunk/samples/toolBarDemo/src/main/webapp/pages/index.jsp 2009-02-09 14:23:17 UTC (rev
12602)
@@ -1,6 +1,10 @@
<%@ taglib
uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib
uri="http://java.sun.com/jsf/core" prefix="f" %>
+<%@ taglib
uri="http://richfaces.org/a4j" prefix="a4j" %>
<%@ taglib
uri="http://labs.jboss.com/jbossrichfaces/ui/toolBar"
prefix="rich"%>
+<%@ taglib
uri="http://labs.jboss.com/jbossrichfaces/ui/dropdown-menu"
prefix="ddm" %>
+<%@ taglib
uri="http://labs.jboss.com/jbossrichfaces/ui/menu-components"
prefix="mc" %>
+
<html>
<style>
.toolbar_sep{
@@ -11,39 +15,63 @@
<body>
<f:view>
- <h:form>
+ <h:form>
<h:selectOneRadio binding="#{skinBean.component}" />
<h:commandLink action="#{skinBean.change}" value="set
skin" />
- </h:form>
-
- <h:form>
- <h:messages style="color:red"/>
- <h:outputText value="Simple richfaces toolBar and toolBarGroup test web
application." style="font: 18px;font-weight: bold;" />
+ </h:form>
- <rich:toolBar id="toolBar_01" width="#{bean.width}"
height="#{bean.height}" itemSeparator="line">
-
- <h:outputText value="Exadel style tool bar." />
-
- <rich:toolBarGroup id="toolBarGroup_01" location="left"
itemSeparator="square">
- <h:outputText value="Set width" />
- <h:inputText value="#{bean.width}"/>
- <h:commandButton value="Change!"/>
- </rich:toolBarGroup>
-
- <rich:toolBarGroup id="toolBarGroup_02" location="left"
itemSeparator="square">
- <h:outputText value="Set height" />
- <h:inputText value="#{bean.height}"/>
- <h:commandButton value="Change!"/>
- </rich:toolBarGroup>
+ <h:form>
+ <rich:toolBar itemSeparator="line">
+ <rich:toolBarGroup itemSeparator="square">
+ <ddm:dropDownMenu value="Seed Multiplication -0- "
submitMode="server" rendered="false">
+ <mc:menuItem value="oncomplete" id="editItem"
submitMode="none">
+ <a4j:support
oncomplete="Richfaces.showModalPanel('_panel');"
event="onclick" />
+ </mc:menuItem>
+ <mc:menuItem value="oncomplete" id="editItem1"
submitMode="none">
+ <a4j:support
oncomplete="Richfaces.showModalPanel('_panel');"
event="onclick" />
+ </mc:menuItem>
+ </ddm:dropDownMenu>
+ <ddm:dropDownMenu value="Field Evaluation -1- "
rendered="false">
+ <mc:menuItem value="View fieldplans" />
+ </ddm:dropDownMenu>
+ <ddm:dropDownMenu value="Field Evaluation -2- "
rendered="true">
+ <mc:menuItem value="View fieldplans" />
+ </ddm:dropDownMenu>
+ </rich:toolBarGroup>
+ </rich:toolBar>
- <rich:toolBarGroup id="toolBarGroup_03" location="right"
itemSeparator="grid">
- <h:graphicImage url="/images/exadel.gif" style="border-width:
0px;" />
- <h:outputLink value="http://exadel.com">
- <h:outputText value="exadel.com"/>
- </h:outputLink>
- </rich:toolBarGroup>
-
- </rich:toolBar>
+
+ <h:messages style="color:red" />
+ <h:outputText value="Simple richfaces toolBar and toolBarGroup test web
application."
+ style="font: 18px;font-weight: bold;" />
+
+ <rich:toolBar id="toolBar_01" width="#{bean.width}"
height="#{bean.height}" itemSeparator="line">
+
+ <h:outputText value="Exadel style tool bar." />
+
+ <rich:toolBarGroup id="toolBarGroup_01"
location="left"
+ itemSeparator="square">
+ <h:outputText value="Set width" />
+ <h:inputText value="#{bean.width}" />
+ <h:commandButton value="Change!" />
+ </rich:toolBarGroup>
+
+ <rich:toolBarGroup id="toolBarGroup_02"
location="left"
+ itemSeparator="square">
+ <h:outputText value="Set height" />
+ <h:inputText value="#{bean.height}" />
+ <h:commandButton value="Change!" />
+ </rich:toolBarGroup>
+
+ <rich:toolBarGroup id="toolBarGroup_03"
location="right"
+ itemSeparator="grid">
+ <h:graphicImage url="/images/exadel.gif"
style="border-width: 0px;" />
+ <h:outputLink value="http://exadel.com">
+ <h:outputText value="exadel.com" />
+ </h:outputLink>
+ </rich:toolBarGroup>
+
+ </rich:toolBar>
<br /><br /><br />
<rich:toolBar id="toolBar_02" width="#{bean.width}"
height="#{bean.height}" itemSeparator="line"
Modified: trunk/ui/dataTable/src/main/java/org/richfaces/component/UIColumnGroup.java
===================================================================
--- trunk/ui/dataTable/src/main/java/org/richfaces/component/UIColumnGroup.java 2009-02-09
10:53:41 UTC (rev 12601)
+++ trunk/ui/dataTable/src/main/java/org/richfaces/component/UIColumnGroup.java 2009-02-09
14:23:17 UTC (rev 12602)
@@ -26,8 +26,6 @@
import javax.faces.component.UIComponent;
import javax.faces.component.UIPanel;
-import org.apache.commons.collections.iterators.FilterIterator;
-
/**
* JSF component class
*
Modified:
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
===================================================================
---
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2009-02-09
10:53:41 UTC (rev 12601)
+++
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2009-02-09
14:23:17 UTC (rev 12602)
@@ -248,44 +248,40 @@
while (headers.hasNext()) {
UIComponent column = (UIComponent) headers.next();
if (isColumnRendered(column)) {
- if ((Integer) column.getAttributes().get("colspan") != null) {
- t_colCount = t_colCount
- + ((Integer) column.getAttributes().get("colspan"))
- .intValue();
+
+ Integer colspan = (Integer) column.getAttributes().get("colspan");
+ if (colspan != null) {
+ t_colCount += colspan.intValue();
} else {
t_colCount++;
}
+
if (t_colCount > colCount) {
break;
}
String classAttribute = facetName + "Class";
- String columnHeaderClass = (String) column.getAttributes().get(
- classAttribute);
+ String columnHeaderClass = (String) column.getAttributes().get(classAttribute);
+
writer.startElement(element, column);
- encodeStyleClass(writer, null, skinCellClass, headerClass,
- columnHeaderClass);
+ encodeStyleClass(writer, null, skinCellClass, headerClass, columnHeaderClass);
writer.writeAttribute("scope", "col", null);
getUtils().encodeAttribute(context, column, "colspan");
- boolean sortableColumn = column
- .getValueExpression("comparator") != null
+ boolean sortableColumn = column.getValueExpression("comparator") != null
|| column.getValueExpression("sortBy") != null;
- HeaderEncodeStrategy strategy = (column instanceof org.richfaces.component.UIColumn
&& "header"
- .equals(facetName)) ? richEncodeStrategy
- : simpleEncodeStrategy;
+ HeaderEncodeStrategy strategy = (column instanceof org.richfaces.component.UIColumn
+ && "header".equals(facetName)) ? richEncodeStrategy :
simpleEncodeStrategy;
- strategy.encodeBegin(context, writer, column, facetName,
- sortableColumn);
+ strategy.encodeBegin(context, writer, column, facetName, sortableColumn);
UIComponent facet = column.getFacet(facetName);
if (facet != null && isColumnRendered(facet)) {
renderChild(context, facet);
}
- strategy.encodeEnd(context, writer, column, facetName,
- sortableColumn);
+ strategy.encodeEnd(context, writer, column, facetName, sortableColumn);
writer.endElement(element);
@@ -294,16 +290,15 @@
}
}
- public void encodeFooter(FacesContext context, UIDataTable table,
- int columns) throws IOException {
+ public void encodeFooter(FacesContext context, UIDataTable table, int columns)
+ throws IOException {
ResponseWriter writer = context.getResponseWriter();
UIComponent footer = table.getFooter();
boolean columnFacetPresent = isColumnFacetPresent(table,"footer");
- Iterator<UIComponent> tableColumns =
table.columns();//columnFacets(table,"footer");
+ Iterator<UIComponent> tableColumns = table.columns();
if (footer != null || columnFacetPresent) {
writer.startElement("tfoot", table);
- String footerClass = (String) table.getAttributes().get(
- "footerClass");
+ String footerClass = (String) table.getAttributes().get("footerClass");
if (columnFacetPresent) {
writer.startElement("tr", table);
Modified: trunk/ui/toolBar/src/main/java/org/richfaces/component/UIToolBarGroup.java
===================================================================
--- trunk/ui/toolBar/src/main/java/org/richfaces/component/UIToolBarGroup.java 2009-02-09
10:53:41 UTC (rev 12601)
+++ trunk/ui/toolBar/src/main/java/org/richfaces/component/UIToolBarGroup.java 2009-02-09
14:23:17 UTC (rev 12602)
@@ -21,6 +21,9 @@
package org.richfaces.component;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
@@ -49,4 +52,17 @@
}
return (UIToolBar) component;
}
+
+ public List<UIComponent> getRenderedChildren() {
+ List<UIComponent> children = this.getChildren();
+ List<UIComponent> renderedChildren = new
ArrayList<UIComponent>(children.size());
+
+ for (UIComponent child : children) {
+ if (child.isRendered()) {
+ renderedChildren.add(child);
+ }
+ }
+
+ return renderedChildren;
+ }
}
Modified:
trunk/ui/toolBar/src/main/java/org/richfaces/renderkit/html/ToolBarGroupRenderer.java
===================================================================
---
trunk/ui/toolBar/src/main/java/org/richfaces/renderkit/html/ToolBarGroupRenderer.java 2009-02-09
10:53:41 UTC (rev 12601)
+++
trunk/ui/toolBar/src/main/java/org/richfaces/renderkit/html/ToolBarGroupRenderer.java 2009-02-09
14:23:17 UTC (rev 12602)
@@ -21,9 +21,7 @@
package org.richfaces.renderkit.html;
-
import java.io.IOException;
-import java.util.Iterator;
import java.util.List;
import javax.faces.component.UIComponent;
@@ -34,56 +32,68 @@
import org.richfaces.component.UIToolBarGroup;
public class ToolBarGroupRenderer extends ToolBarRendererBase {
-
- protected Class getComponentClass() {
- return UIToolBarGroup.class;
- }
+
+ protected Class<?> getComponentClass() {
+ return UIToolBarGroup.class;
+ }
+
+ public boolean getRendersChildren() {
+ return true;
+ }
+
+ public void encodeChildren(FacesContext facesContext, UIComponent component)
+ throws IOException {
+
+ UIToolBarGroup toolBarGroup = (UIToolBarGroup) component;
+ List<UIComponent> renderedChildren = toolBarGroup.getRenderedChildren();
+ if (renderedChildren.size() <= 0) {
+ return;
+ }
- public boolean getRendersChildren() {
- return true;
- }
-
- public void encodeChildren(FacesContext facesContext, UIComponent component) throws
IOException {
- UIToolBarGroup toolBarGroup = (UIToolBarGroup) component;
- ResponseWriter writer = facesContext.getResponseWriter();
- String styleClass = (String) toolBarGroup.getAttributes().get(HTML.STYLE_CLASS_ATTR);
- String contentClass = (String)
getParentToolBar(component).getAttributes().get("contentClass");
- String style = (String) toolBarGroup.getAttributes().get(HTML.style_ATTRIBUTE);
- String contentStyle = (String)
getParentToolBar(component).getAttributes().get("contentStyle");
-
- if (null == contentClass) {
- contentClass = "";
- }
- if (null == styleClass) {
- styleClass = "";
- }
- if (null == contentStyle) {
- contentStyle = "";
- }
- if (null == style) {
- style = "";
- }
-
- if (component.getChildCount() > 0) {
- List<UIComponent> children = component.getChildren();
- for (Iterator<UIComponent> iter = children.iterator(); iter.hasNext();) {
- UIComponent child = (UIComponent) iter.next();
- if(!child.isRendered()){
- iter.remove();
- }
- }
- for (Iterator<UIComponent> it = children.iterator(); it.hasNext();) {
- UIComponent child = (UIComponent) it.next();
- writer.startElement(HTML.td_ELEM, component);
- writer.writeAttribute(HTML.class_ATTRIBUTE, "dr-toolbar-int rich-toolbar-item
" + contentClass + " " + styleClass, null);
- getUtils().writeAttribute(writer, HTML.style_ATTRIBUTE, contentStyle + ";"
+ style);
- encodeEventsAttributes(facesContext, toolBarGroup, writer);
- renderChild(facesContext, child);
- writer.endElement(HTML.td_ELEM);
- if (it.hasNext()) {
- insertSeparatorIfNeed(facesContext, toolBarGroup, writer);
- }
- }
- }
- }
+ ResponseWriter writer = facesContext.getResponseWriter();
+
+
+ renderChild(facesContext, toolBarGroup, writer, renderedChildren.get(0));
+ for (int i = 1; i < renderedChildren.size(); i++) {
+
+ insertSeparatorIfNeed(facesContext, toolBarGroup, writer);
+
+ renderChild(facesContext, toolBarGroup, writer, renderedChildren.get(i));
+ }
+ }
+
+ private void renderChild(FacesContext facesContext,
+ UIToolBarGroup toolBarGroup, ResponseWriter writer,
+ UIComponent child) throws IOException {
+
+ writer.startElement(HTML.td_ELEM, toolBarGroup);
+ writeClassValue(toolBarGroup, writer);
+ writeStyleValue(toolBarGroup, writer);
+ encodeEventsAttributes(facesContext, toolBarGroup, writer);
+
+ super.renderChild(facesContext, child);
+
+ writer.endElement(HTML.td_ELEM);
+ }
+
+ private void writeStyleValue(UIToolBarGroup toolBarGroup, ResponseWriter writer)
throws IOException {
+ String style = getStringAttribute(toolBarGroup, HTML.style_ATTRIBUTE);
+ String contentStyle = getStringAttribute(getParentToolBar(toolBarGroup),
"contentStyle");
+
+ String value = contentStyle + ";" + style;
+ getUtils().writeAttribute(writer, HTML.style_ATTRIBUTE, value);
+ }
+
+ private void writeClassValue(UIToolBarGroup toolBarGroup, ResponseWriter writer)
throws IOException {
+ String styleClass = getStringAttribute(toolBarGroup, HTML.STYLE_CLASS_ATTR);
+ String contentClass = getStringAttribute(getParentToolBar(toolBarGroup),
"contentClass");
+
+ String value = "dr-toolbar-int rich-toolbar-item " + contentClass +
" " + styleClass;
+ writer.writeAttribute(HTML.class_ATTRIBUTE, value, null);
+ }
+
+ private String getStringAttribute(UIComponent toolBarGroup, String attribute) {
+ String value = (String) toolBarGroup.getAttributes().get(attribute);
+ return null == value ? "" : value;
+ }
}