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/11/11 15:26:36 UTC
svn commit: r1769300 - in /myfaces/tobago/trunk:
tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/
tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/
tobago-example/tobago-example-demo/src/main/webapp/c...
Author: lofwyr
Date: Fri Nov 11 15:26:36 2016
New Revision: 1769300
URL: http://svn.apache.org/viewvc?rev=1769300&view=rev
Log:
TOBAGO-1524: Use standard AJAX mechanism
* TabGroup: using standard command JS API instead of proprietary code
Modified:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITab.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SheetTagDeclaration.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TabGroupTagDeclaration.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TabTagDeclaration.java
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/070-tab/01-ajax/tab-ajax.xhtml
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/TabGroupRenderer.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-tab.js
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITab.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITab.java?rev=1769300&r1=1769299&r2=1769300&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITab.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITab.java Fri Nov 11 15:26:36 2016
@@ -19,7 +19,9 @@
package org.apache.myfaces.tobago.internal.component;
-public abstract class AbstractUITab extends AbstractUIPanelBase {
+import javax.faces.component.behavior.ClientBehaviorHolder;
+
+public abstract class AbstractUITab extends AbstractUIPanelBase implements ClientBehaviorHolder {
public abstract String getLabel();
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SheetTagDeclaration.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SheetTagDeclaration.java?rev=1769300&r1=1769299&r2=1769300&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SheetTagDeclaration.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SheetTagDeclaration.java Fri Nov 11 15:26:36 2016
@@ -62,7 +62,7 @@ import javax.faces.component.UIData;
allowedChildComponenents = "org.apache.myfaces.tobago.Reload")},
behaviors = {
@Behavior(
- name = ClientBehaviors.RELOAD,
+ name = ClientBehaviors.RELOAD, // XXX replace by click
isDefault = true)
})
public interface SheetTagDeclaration
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TabGroupTagDeclaration.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TabGroupTagDeclaration.java?rev=1769300&r1=1769299&r2=1769300&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TabGroupTagDeclaration.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TabGroupTagDeclaration.java Fri Nov 11 15:26:36 2016
@@ -53,7 +53,7 @@ import javax.faces.component.UIPanel;
allowedChildComponenents = "org.apache.myfaces.tobago.Tab",
behaviors = {
@Behavior(
- name = ClientBehaviors.RELOAD,
+ name = ClientBehaviors.CLICK,
isDefault = true)
})
public interface TabGroupTagDeclaration
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TabTagDeclaration.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TabTagDeclaration.java?rev=1769300&r1=1769299&r2=1769300&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TabTagDeclaration.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TabTagDeclaration.java Fri Nov 11 15:26:36 2016
@@ -19,9 +19,11 @@
package org.apache.myfaces.tobago.internal.taglib.component;
+import org.apache.myfaces.tobago.apt.annotation.Behavior;
import org.apache.myfaces.tobago.apt.annotation.Facet;
import org.apache.myfaces.tobago.apt.annotation.Tag;
import org.apache.myfaces.tobago.apt.annotation.UIComponentTag;
+import org.apache.myfaces.tobago.component.ClientBehaviors;
import org.apache.myfaces.tobago.component.Facets;
import org.apache.myfaces.tobago.component.RendererTypes;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasAccessKey;
@@ -50,7 +52,12 @@ import javax.faces.component.UIPanel;
rendererType = RendererTypes.TAB,
facets = {
@Facet(name = Facets.BAR,
- description = "Contains some code to be placed in the header at the bar position.")})
+ description = "Contains some code to be placed in the header at the bar position.")},
+ behaviors = {
+ @Behavior(
+ name = ClientBehaviors.CLICK,
+ isDefault = true)
+ })
public interface TabTagDeclaration
extends HasIdBindingAndRendered, IsVisual, HasLabel, HasAccessKey, HasTip, IsDisabled, HasImage {
}
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/070-tab/01-ajax/tab-ajax.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/070-tab/01-ajax/tab-ajax.xhtml?rev=1769300&r1=1769299&r2=1769300&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/070-tab/01-ajax/tab-ajax.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/070-tab/01-ajax/tab-ajax.xhtml Fri Nov 11 15:26:36 2016
@@ -108,16 +108,17 @@
<p>Changed to tab one.</p>
</tc:tab>
<tc:tab label="Two">
+ <!-- <f:ajax render=":page:header:headerInfo"/> -->
<p>Changed to tab two.</p>
</tc:tab>
<tc:tab label="Three">
<p>Changed to tab three.</p>
</tc:tab>
</tc:tabGroup>
- <tc:panel id="outPanel">
+ <tc:box label="Data from the tab group above" id="outPanel">
<tc:out label="NewTabIndex" value="#{tabController.newTabIndex}"/>
<tc:out label="ClientID" value="#{tabController.clientId}"/>
<tc:out label="TabChangedCount" value="#{tabController.count}"/>
- </tc:panel>
+ </tc:box>
</tc:section>
</ui:composition>
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/TabGroupRenderer.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/TabGroupRenderer.java?rev=1769300&r1=1769299&r2=1769300&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/TabGroupRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/TabGroupRenderer.java Fri Nov 11 15:26:36 2016
@@ -20,6 +20,7 @@
package org.apache.myfaces.tobago.renderkit.html.standard.standard.tag;
import org.apache.myfaces.tobago.component.Attributes;
+import org.apache.myfaces.tobago.component.ClientBehaviors;
import org.apache.myfaces.tobago.component.Facets;
import org.apache.myfaces.tobago.component.UITab;
import org.apache.myfaces.tobago.component.UITabGroup;
@@ -29,11 +30,13 @@ import org.apache.myfaces.tobago.event.T
import org.apache.myfaces.tobago.internal.component.AbstractUIPanelBase;
import org.apache.myfaces.tobago.internal.util.AccessKeyLogger;
import org.apache.myfaces.tobago.internal.util.Deprecation;
+import org.apache.myfaces.tobago.internal.util.StringUtils;
import org.apache.myfaces.tobago.model.SwitchType;
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.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;
@@ -56,12 +59,43 @@ import javax.faces.context.FacesContext;
import java.io.IOException;
import java.util.Map;
+//@ListenerFor(systemEventClass = PostAddToViewEvent.class)
+//public class TabGroupRenderer extends RendererBase implements ComponentSystemEventListener {
public class TabGroupRenderer extends RendererBase {
private static final Logger LOG = LoggerFactory.getLogger(TabGroupRenderer.class);
private static final String ACTIVE_INDEX_POSTFIX = ComponentUtils.SUB_SEPARATOR + "activeIndex";
+/* todo
+ @Override
+ public void processEvent(ComponentSystemEvent event) {
+
+ final UITabGroup tabGroup = (UITabGroup) event.getComponent();
+
+ for (final UIComponent child : tabGroup.getChildren()) {
+ if (child instanceof UITab) {
+ final UITab tab = (UITab) child;
+ if (tab.isRendered()) {
+ switch (tabGroup.getSwitchType()) {
+ case client:
+ // todo: implement a client behavior which can call local scripts (respect CSP)
+ break;
+ case reloadTab:
+ final AjaxBehavior ajaxBehavior = new AjaxBehavior();
+ tab.addClientBehavior("click", ajaxBehavior);
+ break;
+ case reloadPage:
+ final EventBehavior eventBehavior = new EventBehavior();
+ tab.addClientBehavior("click", eventBehavior);
+ break;
+ }
+ }
+ }
+ }
+ }
+*/
+
@Override
public void decode(final FacesContext facesContext, final UIComponent component) {
if (ComponentUtils.isOutputOnly(component)) {
@@ -103,10 +137,6 @@ public class TabGroupRenderer extends Re
writer.writeStyleAttribute(tabGroup.getStyle());
writer.writeAttribute(HtmlAttributes.SWITCHTYPE, switchType.name(), false);
-// todo writer.writeCommandMapAttribute(JsonUtils.encode(RenderUtils.getBehaviorCommands(facesContext, tabGroup)));
- final CommandMap commands = RenderUtils.getBehaviorCommands(facesContext, tabGroup);
- writer.writeAttribute(DataAttributes.BEHAVIOR_COMMANDS, JsonUtils.encode(commands), false);
-
writer.startElement(HtmlElements.INPUT);
writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN);
writer.writeAttribute(HtmlAttributes.VALUE, activeIndex);
@@ -165,6 +195,8 @@ public class TabGroupRenderer extends Re
writer.startElement(HtmlElements.UL);
writer.writeClassAttribute(Classes.create(tabGroup, "header"), BootstrapClass.NAV, BootstrapClass.NAV_TABS);
writer.writeAttribute(HtmlAttributes.ROLE, HtmlRoleValues.TABLIST.toString(), false);
+ final String tabGroupId = tabGroup.getClientId(facesContext);
+ final CommandMap additionalCommands = RenderUtils.getBehaviorCommands(facesContext, tabGroup);
int index = 0;
for (final UIComponent child : tabGroup.getChildren()) {
@@ -173,6 +205,7 @@ public class TabGroupRenderer extends Re
if (tab.isRendered()) {
final LabelWithAccessKey label = new LabelWithAccessKey(tab);
final boolean disabled = tab.isDisabled();
+ final String tabId = tab.getClientId(facesContext);
Markup markup = activeIndex == index ? Markup.SELECTED : Markup.NULL;
final FacesMessage.Severity maxSeverity
@@ -182,6 +215,7 @@ public class TabGroupRenderer extends Re
}
writer.startElement(HtmlElements.LI);
+ writer.writeIdAttribute(tabId);
writer.writeClassAttribute(Classes.create(tab, markup), BootstrapClass.NAV_ITEM);
writer.writeAttribute(HtmlAttributes.ROLE, HtmlRoleValues.PRESENTATION.toString(), false);
writer.writeAttribute(HtmlAttributes.TABGROUPINDEX, index);
@@ -190,6 +224,49 @@ public class TabGroupRenderer extends Re
writer.writeAttribute(HtmlAttributes.TITLE, title, true);
}
+// TODO: to be refactored
+//
+//
+//
+//
+ CommandMap map = RenderUtils.getBehaviorCommands(facesContext, tab);
+
+ if (map == null) {
+ map = new CommandMap();
+ }
+
+ // XXX temporary implementation
+ switch (tabGroup.getSwitchType()) {
+ case client:
+ // todo: implement a client behavior which can call local scripts (respect CSP)
+ break;
+ case reloadTab:
+
+ final Command additionalClick = additionalCommands != null ? additionalCommands.getClick() : null;
+
+ String execute = additionalClick != null && StringUtils.isNotBlank(additionalClick.getExecute())
+ ? additionalClick.getExecute() + " " + tabGroupId : tabGroupId;
+ String render = additionalClick != null && StringUtils.isNotBlank(additionalClick.getRender())
+ ? additionalClick.getRender() + " " + tabGroupId : tabGroupId;
+
+ final Command click = map.getClick();
+ if (click != null) {
+
+ execute = StringUtils.isNotBlank(click.getExecute()) ? click.getExecute() + " " + execute : execute;
+ render = StringUtils.isNotBlank(click.getRender()) ? click.getRender() + " " + render : render;
+
+ }
+ map.addCommand(ClientBehaviors.click,
+ new Command(tabId, null, null, execute, render, null, null, null, null, null));
+ break;
+ case reloadPage:
+ map.addCommand(ClientBehaviors.click,
+ new Command(tabId, null, null, null, null, null, null, null, null, null));
+ break;
+ }
+
+ writer.writeAttribute(DataAttributes.COMMANDS, JsonUtils.encode(map), false);
+
writer.startElement(HtmlElements.A);
if (!tab.isDisabled()) {
writer.writeAttribute(DataAttributes.TOGGLE, "tab", false);
@@ -206,8 +283,6 @@ public class TabGroupRenderer extends Re
writer.writeAttribute(
DataAttributes.TARGET, '#' + getTabPanelId(facesContext, tab).replaceAll(":", "\\\\:"), false);
}
- final String tabId = tab.getClientId(facesContext);
- writer.writeIdAttribute(tabId);
if (!disabled && label.getAccessKey() != null) {
writer.writeAttribute(HtmlAttributes.ACCESSKEY, Character.toString(label.getAccessKey()), false);
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-tab.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-tab.js?rev=1769300&r1=1769299&r2=1769300&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-tab.js (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-tab.js Fri Nov 11 15:26:36 2016
@@ -25,53 +25,17 @@ Tobago.TabGroup.init = function(elements
var tabGroups = Tobago.Utils.selectWithJQuery(elements, ".tobago-tabGroup");
- // initialize the tab header elements
- // reload tab case
- tabGroups.filter("[switchType='reloadTab']").each(function() {
- jQuery(this)
- .find(".tobago-tabGroup-header")
- .first()
- .children(".tobago-tab")
- .not(".tobago-tab-markup-disabled")
- .click(
- function (event) {
- var tab = jQuery(this);
- var activeIndex = Tobago.TabGroup.updateHidden(tab);
- console.debug("todo: ajax reload, activeIndex=" + activeIndex); // @DEV_ONLY
- var tabGroup = tab.parents(".tobago-tabGroup:first");
- var tabGroupId = tabGroup.attr("id");
- var executeIds = tabGroupId;
- var renderIds = tabGroupId;
- var behaviorCommands = tabGroup.data("tobago-behavior-commands");
- if (behaviorCommands && behaviorCommands.reload) {
- if (behaviorCommands.reload.execute) {
- executeIds = behaviorCommands.reload.execute;
- }
- if (behaviorCommands.reload.render) {
- renderIds += " " + behaviorCommands.reload.render;
- }
- }
-
- jsf.ajax.request(
- tabGroupId,
- event,
- {
- execute: executeIds,
- render: renderIds
- });
- })
- });
-
- // initialize the tab header elements
- // reload page case
- tabGroups.filter("[switchType='reloadPage']").each(function() {
- jQuery(this).find(".tobago-tabGroup-header").first()
- .children(".tobago-tab").not(".tobago-tab-markup-disabled").click(function() {
- var activeIndex = Tobago.TabGroup.updateHidden(jQuery(this));
- console.debug("todo: full reload, activeIndex=" + activeIndex); // @DEV_ONLY
- var tabGroup = jQuery(this).parents(".tobago-tabGroup:first");
- Tobago.submitAction(tabGroup.eq(0), tabGroup.attr("id"));
- })
+ // setting the active index
+ tabGroups.each(function () {
+ jQuery(this).find(".tobago-tabGroup-header").first().children(".tobago-tab").not(".tobago-tab-markup-disabled")
+ .click(function () {
+ // Update the hidden field for the active index.
+ var tab = jQuery(this);
+ var tabGroup = tab.parents(".tobago-tabGroup:first");
+ var hidden = tabGroup.children("input");
+ var activeIndex = tab.attr("tabgroupindex");
+ hidden.val(activeIndex);
+ })
});
// initialize previous button
@@ -120,18 +84,6 @@ Tobago.TabGroup.init = function(elements
// jQuery('.tobago-tabGroup').show();
};
-/**
- * Update the hidden field for the active index.
- * @param tab is a jQuery object which represents the clicked tab area.
- */
-Tobago.TabGroup.updateHidden = function(tab) {
- var tabGroup = tab.parents(".tobago-tabGroup:first");
- var hidden = tabGroup.children("input");
- var activeIndex = tab.attr("tabgroupindex");
- hidden.val(activeIndex);
- return activeIndex;
-};
-
Tobago.TabGroup.ensureScrollPosition = function (header) {
var tab = header.find(".tobago-tab-markup-selected");
if (tab.length > 0) {