You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2016/04/27 08:40:11 UTC
svn commit: r1741152 - in /myfaces/tobago/trunk:
tobago-core/src/main/java/org/apache/myfaces/tobago/component/
tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/
tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/toba...
Author: lofwyr
Date: Wed Apr 27 06:40:10 2016
New Revision: 1741152
URL: http://svn.apache.org/viewvc?rev=1741152&view=rev
Log:
TOBAGO-1557: Consolidate <tc:button> and <tc:link> with <tc:command>
Modified:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRoleValues.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ButtonRenderer.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/CommandGroupRenderer.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/CommandRenderer.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/CommandRendererBase.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/LinkRenderer.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/TreeCommandRenderer.java
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java?rev=1741152&r1=1741151&r2=1741152&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java Wed Apr 27 06:40:10 2016
@@ -26,6 +26,8 @@ public enum RendererTypes {
Box,
BoxToolBar,
+ /** @deprecated */
+ @Deprecated
Button,
Calendar,
Column,
@@ -44,6 +46,8 @@ public enum RendererTypes {
Hidden,
In,
Image,
+ /** @deprecated */
+ @Deprecated
Link,
Label,
Mediator,
@@ -93,6 +97,8 @@ public enum RendererTypes {
public static final String BOX = "Box";
public static final String BOX_TOOL_BAR = "BoxToolBar";
+ /** @deprecated */
+ @Deprecated
public static final String BUTTON = "Button";
public static final String CALENDAR = "Calendar";
public static final String COLUMN = "Column";
@@ -111,6 +117,8 @@ public enum RendererTypes {
public static final String HIDDEN = "Hidden";
public static final String IN = "In";
public static final String IMAGE = "Image";
+ /** @deprecated */
+ @Deprecated
public static final String LINK = "Link";
public static final String LABEL = "Label";
public static final String MEDIATOR = "Mediator";
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRoleValues.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRoleValues.java?rev=1741152&r1=1741151&r2=1741152&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRoleValues.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRoleValues.java Wed Apr 27 06:40:10 2016
@@ -24,6 +24,7 @@ public enum HtmlRoleValues {
ALERT("alert"),
DIALOG("dialog"),
DOCUMENT("document"),
+ GROUP("group"),
MENU("menu"),
NAVIGATION("navigation"),
PRESENTATION("presentation"),
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java?rev=1741152&r1=1741151&r2=1741152&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java Wed Apr 27 06:40:10 2016
@@ -37,8 +37,9 @@ public enum BootstrapClass implements Cs
ALERT_DISMISSIBLE("alert-dismissible"),
BG_INVERSE("bg-inverse"),
BTN("btn"),
- BTN_SECONDARY("btn-secondary"),
+ BTN_GROUP("btn-group"),
BTN_PRIMARY("btn-primary"),
+ BTN_SECONDARY("btn-secondary"),
CARD("card"),
CARD_BLOCK("card-block"),
CARD_HEADER("card-header"),
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ButtonRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ButtonRenderer.java?rev=1741152&r1=1741151&r2=1741152&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ButtonRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ButtonRenderer.java Wed Apr 27 06:40:10 2016
@@ -20,99 +20,46 @@
package org.apache.myfaces.tobago.renderkit.html.standard.standard.tag;
import org.apache.myfaces.tobago.component.Attributes;
-import org.apache.myfaces.tobago.component.UIButton;
import org.apache.myfaces.tobago.internal.component.AbstractUICommand;
-import org.apache.myfaces.tobago.internal.component.AbstractUIForm;
-import org.apache.myfaces.tobago.internal.component.AbstractUIToolBar;
-import org.apache.myfaces.tobago.internal.util.AccessKeyLogger;
-import org.apache.myfaces.tobago.renderkit.LabelWithAccessKey;
import org.apache.myfaces.tobago.renderkit.css.BootstrapClass;
-import org.apache.myfaces.tobago.renderkit.css.Classes;
-import org.apache.myfaces.tobago.renderkit.html.Command;
-import org.apache.myfaces.tobago.renderkit.html.CommandMap;
-import org.apache.myfaces.tobago.renderkit.html.DataAttributes;
+import org.apache.myfaces.tobago.renderkit.css.CssItem;
import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
import org.apache.myfaces.tobago.renderkit.html.HtmlButtonTypes;
import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
-import org.apache.myfaces.tobago.renderkit.html.JsonUtils;
import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
-import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
import org.apache.myfaces.tobago.util.ComponentUtils;
import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import java.io.IOException;
+import java.util.List;
public class ButtonRenderer extends CommandRendererBase {
- private static final Logger LOG = LoggerFactory.getLogger(ButtonRenderer.class);
-
@Override
- public void encodeEnd(final FacesContext facesContext, final UIComponent component) throws IOException {
-
- final AbstractUICommand button = (AbstractUICommand) component;
- final String clientId = button.getClientId(facesContext);
- final boolean disabled = button.isDisabled();
- final LabelWithAccessKey label = new LabelWithAccessKey(button);
-
+ protected void encodeBeginElement(final FacesContext facesContext, final AbstractUICommand command)
+ throws IOException {
final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
-
writer.startElement(HtmlElements.BUTTON);
writer.writeAttribute(HtmlAttributes.TYPE, HtmlButtonTypes.BUTTON);
- writer.writeNameAttribute(clientId);
- writer.writeIdAttribute(clientId);
- HtmlRendererUtils.writeDataAttributes(facesContext, writer, button);
- final String title = HtmlRendererUtils.getTitleFromTipAndMessages(facesContext, button);
- if (title != null) {
- writer.writeAttribute(HtmlAttributes.TITLE, title, true);
- }
- writer.writeAttribute(HtmlAttributes.DISABLED, disabled);
-
- if (!disabled) {
- writer.writeAttribute(HtmlAttributes.HREF, "#", false);
-
- if (label.getAccessKey() != null) {
- writer.writeAttribute(HtmlAttributes.ACCESSKEY, Character.toString(label.getAccessKey()), false);
- AccessKeyLogger.addAccessKey(facesContext, label.getAccessKey(), clientId);
- }
-
- if (button instanceof UIButton) {
- writer.writeAttribute(HtmlAttributes.TABINDEX, ((UIButton) button).getTabIndex());
- }
-
- String commands = RenderUtils.getBehaviorCommands(facesContext, button);
- if (commands == null) { // old way
- final CommandMap map = new CommandMap(new Command(facesContext, button));
- commands = JsonUtils.encode(map);
- }
- writer.writeAttribute(DataAttributes.COMMANDS, commands, true);
- }
-
- writer.writeStyleAttribute(button.getStyle());
-
- final boolean defaultCommand = ComponentUtils.getBooleanAttribute(button, Attributes.defaultCommand);
- // TODO this might be too expensive:
- // TODO please put a flag in the ToolBar-handler and Button-handler (facelets-handler)
- final boolean insideToolbar = ComponentUtils.findAncestor(button, AbstractUIToolBar.class) != null;
- writer.writeClassAttribute(
- Classes.create(button),
- BootstrapClass.BTN,
- defaultCommand ? BootstrapClass.BTN_PRIMARY : BootstrapClass.BTN_SECONDARY,
- insideToolbar ? BootstrapClass.NAVBAR_BTN : null,
- button.getCustomClass());
-
- if (defaultCommand) {
- final AbstractUIForm form = ComponentUtils.findAncestor(button, AbstractUIForm.class);
- writer.writeAttribute(DataAttributes.DEFAULT, form.getClientId(facesContext), false);
- }
- writer.flush(); // force closing the start tag
-
- String image = ComponentUtils.getStringAttribute(button, Attributes.image);
- HtmlRendererUtils.encodeIconWithLabel(writer, facesContext, image, label, disabled);
+ }
+ @Override
+ protected void encodeEndElement(final FacesContext facesContext, final AbstractUICommand command)
+ throws IOException {
+ final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
writer.endElement(HtmlElements.BUTTON);
}
+
+ @Override
+ protected void addCssItems(
+ final FacesContext facesContext, final AbstractUICommand command, final List<CssItem> collected) {
+
+ final boolean defaultCommand = ComponentUtils.getBooleanAttribute(command, Attributes.defaultCommand);
+
+ collected.add(BootstrapClass.BTN);
+ collected.add(defaultCommand ? BootstrapClass.BTN_PRIMARY : BootstrapClass.BTN_SECONDARY);
+// todo collected.add(insideToolbar ? BootstrapClass.NAVBAR_BTN : null);
+ }
+
}
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/CommandGroupRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/CommandGroupRenderer.java?rev=1741152&r1=1741151&r2=1741152&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/CommandGroupRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/CommandGroupRenderer.java Wed Apr 27 06:40:10 2016
@@ -19,11 +19,15 @@
package org.apache.myfaces.tobago.renderkit.html.standard.standard.tag;
+import org.apache.myfaces.tobago.component.UINav;
import org.apache.myfaces.tobago.internal.component.AbstractUIForm;
import org.apache.myfaces.tobago.renderkit.RendererBase;
import org.apache.myfaces.tobago.renderkit.css.BootstrapClass;
+import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
+import org.apache.myfaces.tobago.renderkit.html.HtmlRoleValues;
import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
+import org.apache.myfaces.tobago.util.ComponentUtils;
import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
import javax.faces.component.UIComponent;
@@ -36,9 +40,19 @@ public class CommandGroupRenderer extend
public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
- writer.startElement(HtmlElements.UL);
- writer.writeClassAttribute(BootstrapClass.NAV, BootstrapClass.NAVBAR_NAV);
- writer.writeIdAttribute(component.getClientId(facesContext));
+ // fixme: only a temporary workaround
+ final UINav nav = ComponentUtils.findAncestor(component, UINav.class);
+
+ if (nav == null) {
+ writer.startElement(HtmlElements.DIV);
+ writer.writeClassAttribute(BootstrapClass.BTN_GROUP, BootstrapClass.NAVBAR_NAV);
+ writer.writeIdAttribute(component.getClientId(facesContext));
+ writer.writeAttribute(HtmlAttributes.ROLE, HtmlRoleValues.GROUP.toString(), false);
+ } else {
+ writer.startElement(HtmlElements.UL);
+ writer.writeClassAttribute(BootstrapClass.NAV, BootstrapClass.NAVBAR_NAV);
+ writer.writeIdAttribute(component.getClientId(facesContext));
+ }
}
@Override
@@ -55,10 +69,16 @@ public class CommandGroupRenderer extend
if (child instanceof AbstractUIForm) { // XXX hack! TBD: How to walk through the children, or do that in JS?
encodeChildren(facesContext, child);
} else {
- writer.startElement(HtmlElements.LI);
- writer.writeClassAttribute(BootstrapClass.NAV_ITEM, BootstrapClass.DROPDOWN);
- child.encodeAll(facesContext);
- writer.endElement(HtmlElements.LI);
+ // fixme: only a temporary workaround
+ final UINav nav = ComponentUtils.findAncestor(component, UINav.class);
+ if (nav == null) {
+ child.encodeAll(facesContext);
+ } else {
+ writer.startElement(HtmlElements.LI);
+ writer.writeClassAttribute(BootstrapClass.NAV_ITEM, BootstrapClass.DROPDOWN);
+ child.encodeAll(facesContext);
+ writer.endElement(HtmlElements.LI);
+ }
}
}
}
@@ -67,6 +87,12 @@ public class CommandGroupRenderer extend
@Override
public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
- writer.endElement(HtmlElements.UL);
+ // fixme: only a temporary workaround
+ final UINav nav = ComponentUtils.findAncestor(component, UINav.class);
+ if (nav == null) {
+ writer.endElement(HtmlElements.DIV);
+ } else {
+ writer.endElement(HtmlElements.UL);
+ }
}
}
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/CommandRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/CommandRenderer.java?rev=1741152&r1=1741151&r2=1741152&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/CommandRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/CommandRenderer.java Wed Apr 27 06:40:10 2016
@@ -19,168 +19,6 @@
package org.apache.myfaces.tobago.renderkit.html.standard.standard.tag;
-import org.apache.myfaces.tobago.context.ResourceManagerUtils;
-import org.apache.myfaces.tobago.internal.component.AbstractUICommand;
-import org.apache.myfaces.tobago.internal.component.AbstractUILink;
-import org.apache.myfaces.tobago.internal.util.AccessKeyLogger;
-import org.apache.myfaces.tobago.renderkit.LabelWithAccessKey;
-import org.apache.myfaces.tobago.renderkit.css.BootstrapClass;
-import org.apache.myfaces.tobago.renderkit.css.Classes;
-import org.apache.myfaces.tobago.renderkit.css.CssItem;
-import org.apache.myfaces.tobago.renderkit.css.TobagoClass;
-import org.apache.myfaces.tobago.renderkit.html.Command;
-import org.apache.myfaces.tobago.renderkit.html.CommandMap;
-import org.apache.myfaces.tobago.renderkit.html.DataAttributes;
-import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
-import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
-import org.apache.myfaces.tobago.renderkit.html.HtmlRoleValues;
-import org.apache.myfaces.tobago.renderkit.html.JsonUtils;
-import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
-import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import java.io.IOException;
-
public class CommandRenderer extends CommandRendererBase {
-/*
- @Override
- public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
- final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
-
- }
-
- @Override
- public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
- final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
- }
-*/
-
- @Override
- public void encodeBegin(final FacesContext facesContext, final UIComponent component) throws IOException {
-
- final AbstractUICommand link = (AbstractUICommand) component;
- final String clientId = link.getClientId(facesContext);
- final boolean disabled = link.isDisabled();
- final LabelWithAccessKey label = new LabelWithAccessKey(link);
-
- final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
-
- if (disabled) {
- writer.startElement(HtmlElements.SPAN);
- } else {
- writer.startElement(HtmlElements.A);
-
- final CommandMap map = new CommandMap(new Command(facesContext, link));
- writer.writeAttribute(DataAttributes.COMMANDS, JsonUtils.encode(map), true);
-
- writer.writeAttribute(HtmlAttributes.HREF, "#", false);
-
- if (label.getAccessKey() != null) {
- writer.writeAttribute(HtmlAttributes.ACCESSKEY, Character.toString(label.getAccessKey()), false);
- AccessKeyLogger.addAccessKey(facesContext, label.getAccessKey(), clientId);
- }
-
- writer.writeAttribute(HtmlAttributes.TABINDEX,
- link instanceof AbstractUILink ? ((AbstractUILink) link).getTabIndex() : null);
- }
- HtmlRendererUtils.writeDataAttributes(facesContext, writer, link);
- writer.writeStyleAttribute(link.getStyle());
- if (link.isParentOfCommands()) {
- // XXX BootstrapClass.NAV_LINK should only be shown inside of UINav or UIButtonGroup
- writer.writeClassAttribute(BootstrapClass.DROPDOWN_TOGGLE, BootstrapClass.NAV_LINK); // todo: CSS classes
- writer.writeAttribute(DataAttributes.TOGGLE, "dropdown", false);
- } else {
- writer.writeClassAttribute(Classes.create(link), link.getCustomClass());
- }
- writer.writeIdAttribute(clientId);
- writer.writeNameAttribute(clientId);
- final String title = HtmlRendererUtils.getTitleFromTipAndMessages(facesContext, link);
- if (title != null) {
- writer.writeAttribute(HtmlAttributes.TITLE, title, true);
- }
- writer.flush();
-
-// image
- String image = link instanceof AbstractUILink ? ((AbstractUILink) link).getImage() : null;
- if (image != null) {
- if (ResourceManagerUtils.isAbsoluteResource(image)) {
- // absolute Path to image : nothing to do
- } else {
- image = HtmlRendererUtils.getImageWithPath(facesContext, image, disabled);
- }
- writer.startElement(HtmlElements.IMG);
- writer.writeClassAttribute(Classes.create(link, "image"));
- writer.writeAttribute(HtmlAttributes.SRC, image, true);
- final String tip = link.getTip();
- writer.writeAttribute(HtmlAttributes.ALT, tip != null ? tip : "", true);
- if (tip != null) {
- writer.writeAttribute(HtmlAttributes.TITLE, tip, true);
- }
- writer.endElement(HtmlElements.IMG);
- }
-
-// label
- if (label.getLabel() != null) {
- if (image != null) {
- writer.write(" "); // separator: e.g.
- }
- HtmlRendererUtils.writeLabelWithAccessKey(writer, label);
- }
-
- if (disabled) {
- writer.endElement(HtmlElements.SPAN);
- } else {
- writer.endElement(HtmlElements.A);
- }
-
- if (link.isParentOfCommands()) {
- writer.startElement(HtmlElements.UL);
- writer.writeClassAttribute(BootstrapClass.DROPDOWN_MENU);
- writer.writeAttribute(HtmlAttributes.ROLE, HtmlRoleValues.MENU.toString(), false);
- }
- }
-
- @Override
- public boolean getRendersChildren() {
- return true;
- }
-
- @Override
- public void encodeChildren(final FacesContext facesContext, final UIComponent component) throws IOException {
-
- final AbstractUICommand link = (AbstractUICommand) component;
-
- if (link.isParentOfCommands()) {
- final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
-
- for (UIComponent child : component.getChildren()) {
- if (child.isRendered()) {
- writer.startElement(HtmlElements.LI);
- CssItem submenu = child instanceof AbstractUICommand && ((AbstractUICommand) child).isParentOfCommands()
- ? TobagoClass.DROPDOWN_SUBMENU : null;
- // fixme: this name comes not from bootstrap, using prefix? tobago-command-dropdown-submenu
- writer.writeClassAttribute(BootstrapClass.DROPDOWN_ITEM, submenu);
- child.encodeAll(facesContext);
- writer.endElement(HtmlElements.LI);
- }
- }
- } else {
- super.encodeChildren(facesContext, component);
- }
-
- }
-
- @Override
- public void encodeEnd(final FacesContext facesContext, final UIComponent component) throws IOException {
-
- final AbstractUICommand link = (AbstractUICommand) component;
-
- if (link.isParentOfCommands()) {
- final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
- writer.endElement(HtmlElements.UL);
- }
-
- }
}
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/CommandRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/CommandRendererBase.java?rev=1741152&r1=1741151&r2=1741152&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/CommandRendererBase.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/CommandRendererBase.java Wed Apr 27 06:40:10 2016
@@ -19,18 +19,42 @@
package org.apache.myfaces.tobago.renderkit.html.standard.standard.tag;
+import org.apache.myfaces.tobago.component.Attributes;
+import org.apache.myfaces.tobago.internal.component.AbstractUICommand;
+import org.apache.myfaces.tobago.internal.component.AbstractUIForm;
+import org.apache.myfaces.tobago.internal.component.AbstractUIToolBar;
+import org.apache.myfaces.tobago.internal.util.AccessKeyLogger;
+import org.apache.myfaces.tobago.renderkit.LabelWithAccessKey;
import org.apache.myfaces.tobago.renderkit.RendererBase;
+import org.apache.myfaces.tobago.renderkit.css.BootstrapClass;
+import org.apache.myfaces.tobago.renderkit.css.Classes;
+import org.apache.myfaces.tobago.renderkit.css.CssItem;
+import org.apache.myfaces.tobago.renderkit.css.TobagoClass;
+import org.apache.myfaces.tobago.renderkit.html.Command;
+import org.apache.myfaces.tobago.renderkit.html.CommandMap;
+import org.apache.myfaces.tobago.renderkit.html.DataAttributes;
+import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
+import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
+import org.apache.myfaces.tobago.renderkit.html.HtmlRoleValues;
+import org.apache.myfaces.tobago.renderkit.html.JsonUtils;
+import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
+import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
import org.apache.myfaces.tobago.util.ComponentUtils;
+import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
public abstract class CommandRendererBase extends RendererBase {
private static final Logger LOG = LoggerFactory.getLogger(CommandRendererBase.class);
+ private CssItem cssItems;
@Override
public void decode(final FacesContext facesContext, final UIComponent component) {
@@ -52,8 +76,169 @@ public abstract class CommandRendererBas
}
}
+ @Override
+ public void encodeBegin(final FacesContext facesContext, final UIComponent component) throws IOException {
+
+ final AbstractUICommand command = (AbstractUICommand) component;
+ final String clientId = command.getClientId(facesContext);
+ final boolean disabled = command.isDisabled();
+ final LabelWithAccessKey label = new LabelWithAccessKey(command);
+
+ final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
+
+ encodeBeginElement(facesContext, command);
+ writer.writeIdAttribute(clientId);
+ writer.writeNameAttribute(clientId);
+ writer.writeAttribute(HtmlAttributes.DISABLED, disabled);
+
+ if (!disabled) {
+ String commands = RenderUtils.getBehaviorCommands(facesContext, command);
+ if (commands == null) { // old way
+ final CommandMap map = new CommandMap(new Command(facesContext, command));
+ commands = JsonUtils.encode(map);
+ }
+ writer.writeAttribute(DataAttributes.COMMANDS, commands, true);
+
+ writer.writeAttribute(HtmlAttributes.HREF, "#", false);
+
+ if (label.getAccessKey() != null) {
+ writer.writeAttribute(HtmlAttributes.ACCESSKEY, Character.toString(label.getAccessKey()), false);
+ AccessKeyLogger.addAccessKey(facesContext, label.getAccessKey(), clientId);
+ }
+
+ final int tabIndex = ComponentUtils.getIntAttribute(command, Attributes.tabIndex);
+ if (tabIndex != 0) {
+ writer.writeAttribute(HtmlAttributes.TABINDEX, tabIndex);
+ }
+ }
+
+ HtmlRendererUtils.writeDataAttributes(facesContext, writer, command);
+ writer.writeStyleAttribute(command.getStyle());
+
+ if (command.isParentOfCommands()) {
+ // XXX BootstrapClass.NAV_LINK should only be shown inside of UINav or UIButtonGroup
+ writer.writeClassAttribute(BootstrapClass.DROPDOWN_TOGGLE, BootstrapClass.NAV_LINK); // todo: CSS classes
+ writer.writeAttribute(DataAttributes.TOGGLE, "dropdown", false);
+ } else {
+ final List<CssItem> cssItems = new ArrayList<CssItem>();
+ cssItems.add(command.getCustomClass());
+ addCssItems(facesContext, command, cssItems);
+ writer.writeClassAttribute(Classes.create(command), cssItems.toArray(new CssItem[cssItems.size()]));
+ }
+ final String title = HtmlRendererUtils.getTitleFromTipAndMessages(facesContext, command);
+ if (title != null) {
+ writer.writeAttribute(HtmlAttributes.TITLE, title, true);
+ }
+
+ final boolean defaultCommand = ComponentUtils.getBooleanAttribute(command, Attributes.defaultCommand);
+ // TODO this might be too expensive:
+ // TODO please put a flag in the ToolBar-handler and Button-handler (facelets-handler)
+ final boolean insideToolbar = ComponentUtils.findAncestor(command, AbstractUIToolBar.class) != null;
+ writer.writeClassAttribute(
+ Classes.create(command),
+ BootstrapClass.BTN,
+ defaultCommand ? BootstrapClass.BTN_PRIMARY : BootstrapClass.BTN_SECONDARY,
+ insideToolbar ? BootstrapClass.NAVBAR_BTN : null,
+ command.getCustomClass());
+
+ if (defaultCommand) {
+ final AbstractUIForm form = ComponentUtils.findAncestor(command, AbstractUIForm.class);
+ writer.writeAttribute(DataAttributes.DEFAULT, form.getClientId(facesContext), false);
+ }
+
+/*
+// image
+
+ String image = command instanceof AbstractUILink ? ((AbstractUILink) command).getImage() : null;
+ if (image != null) {
+ if (ResourceManagerUtils.isAbsoluteResource(image)) {
+ // absolute Path to image : nothing to do
+ } else {
+ image = HtmlRendererUtils.getImageWithPath(facesContext, image, disabled);
+ }
+ HtmlRendererUtils.encodeIconWithLabel(writer, facesContext, image, label, disabled);
+ }
+
+// label
+ if (label.getLabel() != null) {
+ if (image != null) {
+ writer.write(" "); // separator: e.g.
+ }
+ HtmlRendererUtils.writeLabelWithAccessKey(writer, label);
+ }
+*/
+
+ final String image = ComponentUtils.getStringAttribute(command, Attributes.image);
+ HtmlRendererUtils.encodeIconWithLabel(writer, facesContext, image, label, disabled);
+
+ encodeEndElement(facesContext, command);
+
+ if (command.isParentOfCommands()) {
+ writer.startElement(HtmlElements.UL);
+ writer.writeClassAttribute(BootstrapClass.DROPDOWN_MENU);
+ writer.writeAttribute(HtmlAttributes.ROLE, HtmlRoleValues.MENU.toString(), false);
+ }
+ }
+
+ @Override
+ public boolean getRendersChildren() {
+ return true;
+ }
+
+ @Override
+ public void encodeChildren(final FacesContext facesContext, final UIComponent component) throws IOException {
+
+ final AbstractUICommand link = (AbstractUICommand) component;
+
+ if (link.isParentOfCommands()) {
+ final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
+
+ for (UIComponent child : component.getChildren()) {
+ if (child.isRendered()) {
+ writer.startElement(HtmlElements.LI);
+ CssItem submenu = child instanceof AbstractUICommand && ((AbstractUICommand) child).isParentOfCommands()
+ ? TobagoClass.DROPDOWN_SUBMENU : null;
+ // fixme: this name comes not from bootstrap, using prefix? tobago-command-dropdown-submenu
+ writer.writeClassAttribute(BootstrapClass.DROPDOWN_ITEM, submenu);
+ child.encodeAll(facesContext);
+ writer.endElement(HtmlElements.LI);
+ }
+ }
+ } else {
+ super.encodeChildren(facesContext, component);
+ }
+
+ }
+
+ @Override
+ public void encodeEnd(final FacesContext facesContext, final UIComponent component) throws IOException {
+
+ final AbstractUICommand link = (AbstractUICommand) component;
+
+ if (link.isParentOfCommands()) {
+ final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
+ writer.endElement(HtmlElements.UL);
+ }
+
+ }
+
+ protected void encodeBeginElement(final FacesContext facesContext, final AbstractUICommand command)
+ throws IOException {
+ final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
+ writer.startElement(HtmlElements.A);
+ }
+
+ protected void encodeEndElement(final FacesContext facesContext, final AbstractUICommand command)
+ throws IOException {
+ final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
+ writer.endElement(HtmlElements.A);
+ }
+
protected void commandActivated(final UIComponent component) {
component.queueEvent(new ActionEvent(component));
}
+ protected void addCssItems(
+ final FacesContext facesContext, final AbstractUICommand command, final List<CssItem> collected) {
+ }
}
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/LinkRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/LinkRenderer.java?rev=1741152&r1=1741151&r2=1741152&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/LinkRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/LinkRenderer.java Wed Apr 27 06:40:10 2016
@@ -19,76 +19,6 @@
package org.apache.myfaces.tobago.renderkit.html.standard.standard.tag;
-import org.apache.myfaces.tobago.internal.component.AbstractUILink;
-import org.apache.myfaces.tobago.internal.util.AccessKeyLogger;
-import org.apache.myfaces.tobago.renderkit.LabelWithAccessKey;
-import org.apache.myfaces.tobago.renderkit.css.Classes;
-import org.apache.myfaces.tobago.renderkit.html.Command;
-import org.apache.myfaces.tobago.renderkit.html.CommandMap;
-import org.apache.myfaces.tobago.renderkit.html.DataAttributes;
-import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
-import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
-import org.apache.myfaces.tobago.renderkit.html.JsonUtils;
-import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
-import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import java.io.IOException;
-
public class LinkRenderer extends CommandRendererBase {
- @Override
- public void encodeBegin(final FacesContext facesContext, final UIComponent component) throws IOException {
-
- final AbstractUILink link = (AbstractUILink) component;
- final String clientId = link.getClientId(facesContext);
- final boolean disabled = link.isDisabled();
- final LabelWithAccessKey label = new LabelWithAccessKey(link);
-
- final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
-
- if (disabled) {
- writer.startElement(HtmlElements.SPAN);
- } else {
- writer.startElement(HtmlElements.A);
-
- final CommandMap map = new CommandMap(new Command(facesContext, link));
- writer.writeAttribute(DataAttributes.COMMANDS, JsonUtils.encode(map), true);
-
- writer.writeAttribute(HtmlAttributes.HREF, "#", false);
-
- if (label.getAccessKey() != null) {
- writer.writeAttribute(HtmlAttributes.ACCESSKEY, Character.toString(label.getAccessKey()), false);
- AccessKeyLogger.addAccessKey(facesContext, label.getAccessKey(), clientId);
- }
-
- writer.writeAttribute(HtmlAttributes.TABINDEX, link.getTabIndex());
- }
- HtmlRendererUtils.writeDataAttributes(facesContext, writer, link);
- writer.writeStyleAttribute(link.getStyle());
- writer.writeClassAttribute(Classes.create(link), link.getCustomClass());
- writer.writeIdAttribute(clientId);
- writer.writeNameAttribute(clientId);
- final String title = HtmlRendererUtils.getTitleFromTipAndMessages(facesContext, link);
- if (title != null) {
- writer.writeAttribute(HtmlAttributes.TITLE, title, true);
- }
- writer.flush();
-
-// image
- String image = link.getImage();
- HtmlRendererUtils.encodeIconWithLabel(writer, facesContext, image, label, disabled);
- }
-
- @Override
- public void encodeEnd(final FacesContext facesContext, final UIComponent component) throws IOException {
- final AbstractUILink link = (AbstractUILink) component;
- final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
- if (link.isDisabled()) {
- writer.endElement(HtmlElements.SPAN);
- } else {
- writer.endElement(HtmlElements.A);
- }
- }
}
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/TreeCommandRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/TreeCommandRenderer.java?rev=1741152&r1=1741151&r2=1741152&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/TreeCommandRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/TreeCommandRenderer.java Wed Apr 27 06:40:10 2016
@@ -19,68 +19,5 @@
package org.apache.myfaces.tobago.renderkit.html.standard.standard.tag;
-import org.apache.myfaces.tobago.component.UITreeCommand;
-import org.apache.myfaces.tobago.internal.util.AccessKeyLogger;
-import org.apache.myfaces.tobago.renderkit.LabelWithAccessKey;
-import org.apache.myfaces.tobago.renderkit.css.Classes;
-import org.apache.myfaces.tobago.renderkit.css.Style;
-import org.apache.myfaces.tobago.renderkit.html.Command;
-import org.apache.myfaces.tobago.renderkit.html.CommandMap;
-import org.apache.myfaces.tobago.renderkit.html.DataAttributes;
-import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
-import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
-import org.apache.myfaces.tobago.renderkit.html.JsonUtils;
-import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
-import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import java.io.IOException;
-
public class TreeCommandRenderer extends CommandRendererBase {
-
- @Override
- public void encodeBegin(final FacesContext facesContext, final UIComponent component) throws IOException {
-
- final UITreeCommand command = (UITreeCommand) component;
- final String clientId = command.getClientId(facesContext);
- final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
- final LabelWithAccessKey label = new LabelWithAccessKey(command);
- final boolean disabled = command.isDisabled();
-
- if (disabled) {
- writer.startElement(HtmlElements.SPAN);
- } else {
- writer.startElement(HtmlElements.A);
- final CommandMap map = new CommandMap(new Command(facesContext, command));
- writer.writeAttribute(DataAttributes.COMMANDS, JsonUtils.encode(map), true);
- writer.writeNameAttribute(clientId);
- }
- writer.writeStyleAttribute(command.getStyle() != null ? command.getStyle() : new Style());
- writer.writeClassAttribute(Classes.create(command));
- writer.writeIdAttribute(clientId);
- HtmlRendererUtils.writeDataAttributes(facesContext, writer, command);
- if (!disabled && label.getAccessKey() != null) {
- writer.writeAttribute(HtmlAttributes.ACCESSKEY, Character.toString(label.getAccessKey()), false);
- AccessKeyLogger.addAccessKey(facesContext, label.getAccessKey(), clientId);
- }
- final String title = HtmlRendererUtils.getTitleFromTipAndMessages(facesContext, command);
- if (title != null) {
- writer.writeAttribute(HtmlAttributes.TITLE, title, true);
- }
- writer.flush();
-
- HtmlRendererUtils.writeLabelWithAccessKey(writer, label);
- }
-
- @Override
- public void encodeEnd(final FacesContext facesContext, final UIComponent component) throws IOException {
- final UITreeCommand command = (UITreeCommand) component;
- final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
- if (command.isDisabled()) {
- writer.endElement(HtmlElements.SPAN);
- } else {
- writer.endElement(HtmlElements.A);
- }
- }
}