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/02/10 10:44:24 UTC
svn commit: r1729565 - in /myfaces/tobago/branches/tobago-3.0.x:
tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/
tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/
tobago-example/tobago-example-demo/src/main/webapp/ ...
Author: lofwyr
Date: Wed Feb 10 09:44:24 2016
New Revision: 1729565
URL: http://svn.apache.org/viewvc?rev=1729565&view=rev
Log:
TOBAGO-1524: Use standard ajax mechanism
Progress:
* Writing a basic AjaxClientBehaviorRenderer which prepares the data to be writable into data attributes
* Basic support for <f:ajax> in <tc:button>
Added:
myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/AjaxClientBehaviorRenderer.java
Modified:
myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUICommand.java
myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java
myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/50-partial/partial.xhtml
myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/menu.xhtml
myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/Command.java
myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ButtonRenderer.java
myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java
myfaces/tobago/branches/tobago-3.0.x/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/FacesConfigGenerator.java
Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUICommand.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUICommand.java?rev=1729565&r1=1729564&r2=1729565&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUICommand.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUICommand.java Wed Feb 10 09:44:24 2016
@@ -29,14 +29,20 @@ import org.apache.myfaces.tobago.util.Co
import javax.faces.component.UICommand;
import javax.faces.component.UIComponent;
+import javax.faces.component.behavior.ClientBehaviorHolder;
import javax.faces.context.FacesContext;
import javax.faces.event.FacesEvent;
import javax.faces.event.PhaseId;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Iterator;
public abstract class AbstractUICommand
extends UICommand
- implements SupportsRenderedPartially, SupportsAccessKey, OnComponentPopulated, Visual {
+ implements SupportsRenderedPartially, SupportsAccessKey, OnComponentPopulated, Visual, ClientBehaviorHolder {
+
+ // todo generate
+ private static final Collection<String> EVENT_NAMES = Arrays.asList("click");
// todo: transient
private Boolean parentOfCommands;
@@ -100,6 +106,18 @@ public abstract class AbstractUICommand
return parentOfCommands;
}
+ // todo generate
+ @Override
+ public String getDefaultEventName() {
+ return "click";
+ }
+
+ // todo generate
+ @Override
+ public Collection<String> getEventNames() {
+ return EVENT_NAMES;
+ }
+
public abstract String getLabel();
public abstract boolean isJsfResource();
Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java?rev=1729565&r1=1729564&r2=1729565&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java Wed Feb 10 09:44:24 2016
@@ -36,6 +36,7 @@ import javax.faces.FactoryFinder;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseStream;
import javax.faces.context.ResponseWriter;
+import javax.faces.render.ClientBehaviorRenderer;
import javax.faces.render.RenderKit;
import javax.faces.render.RenderKitFactory;
import javax.faces.render.Renderer;
@@ -43,19 +44,22 @@ import javax.faces.render.ResponseStateM
import java.io.OutputStream;
import java.io.Writer;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
public class TobagoRenderKit extends RenderKit {
private static final Logger LOG = LoggerFactory.getLogger(TobagoRenderKit.class);
- public static final String RENDER_KIT_ID = "tobago";
-
- private RenderKit htmlBasicRenderKit;
+ private final RenderKit htmlBasicRenderKit;
private Map<Key, Renderer> renderers = new HashMap<Key, Renderer>();
public TobagoRenderKit() {
+ RenderKitFactory rkFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ htmlBasicRenderKit =
+ rkFactory.getRenderKit(FacesContext.getCurrentInstance(), RenderKitFactory.HTML_BASIC_RENDER_KIT);
+ LOG.error("Creating TobagoRenderKit with base: {}", htmlBasicRenderKit);
if (LOG.isDebugEnabled()) {
LOG.debug("Creating TobagoRenderKit");
}
@@ -65,8 +69,7 @@ public class TobagoRenderKit extends Ren
public Renderer getRenderer(final String family, final String rendererType) {
Renderer renderer = renderers.get(new Key(family, rendererType));
if (renderer == null) {
- final RenderKit renderKit = getHtmlBasicRenderKit();
- renderer = renderKit.getRenderer(family, rendererType);
+ renderer = htmlBasicRenderKit.getRenderer(family, rendererType);
if (renderer != null) {
renderer = new RendererBaseWrapper(renderer);
}
@@ -80,15 +83,6 @@ public class TobagoRenderKit extends Ren
return renderer;
}
- private RenderKit getHtmlBasicRenderKit() {
- if (htmlBasicRenderKit == null) {
- final RenderKitFactory rkFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
- htmlBasicRenderKit =
- rkFactory.getRenderKit(FacesContext.getCurrentInstance(), RenderKitFactory.HTML_BASIC_RENDER_KIT);
- }
- return htmlBasicRenderKit;
- }
-
@Override
public ResponseWriter createResponseWriter(
final Writer writer, final String contentTypeList, final String characterEncoding) {
@@ -145,12 +139,24 @@ public class TobagoRenderKit extends Ren
@Override
public ResponseStateManager getResponseStateManager() {
- return getHtmlBasicRenderKit().getResponseStateManager();
+ return htmlBasicRenderKit.getResponseStateManager();
}
@Override
public ResponseStream createResponseStream(final OutputStream outputStream) {
- return getHtmlBasicRenderKit().createResponseStream(outputStream);
+ return htmlBasicRenderKit.createResponseStream(outputStream);
+ }
+
+ public void addClientBehaviorRenderer(String type, ClientBehaviorRenderer renderer) {
+ htmlBasicRenderKit.addClientBehaviorRenderer(type, renderer);
+ }
+
+ public ClientBehaviorRenderer getClientBehaviorRenderer(String type) {
+ return htmlBasicRenderKit.getClientBehaviorRenderer(type);
+ }
+
+ public Iterator<String> getClientBehaviorRendererTypes() {
+ return htmlBasicRenderKit.getClientBehaviorRendererTypes();
}
private static final class Key {
Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/50-partial/partial.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/50-partial/partial.xhtml?rev=1729565&r1=1729564&r2=1729565&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/50-partial/partial.xhtml (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/50-partial/partial.xhtml Wed Feb 10 09:44:24 2016
@@ -86,8 +86,11 @@
<tc:gridLayout columns="*;*" rows="auto;auto;auto;auto;auto;auto;auto"/>
</f:facet>
+ <!--renderedPartially="left :page:header:headerInfo"-->
<tc:button label="Reload left" tip="Reload left side box"
- action="#{partialReloadController.reload}" renderedPartially="left :page:header:headerInfo"/>
+ action="#{partialReloadController.reload}">
+ <f:ajax render="left :page:header:headerInfo"/>
+ </tc:button>
<tc:button label="Reload right" tip="Reload right side box"
action="#{partialReloadController.reload}" renderedPartially="right :page:header:headerInfo"/>
Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/menu.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/menu.xhtml?rev=1729565&r1=1729564&r2=1729565&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/menu.xhtml (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/menu.xhtml Wed Feb 10 09:44:24 2016
@@ -23,7 +23,7 @@
<tc:nav image="image/feather-leaf.png" label="Tobago Demo">
- <tc:form>
+ <tc:form id="header">
<tc:commandGroup>
@@ -81,7 +81,7 @@
</tc:commandGroup>
<!-- TBD: this is not nice: can we put tc:out or tc:label into the menu? -->
- <tc:commandGroup>
+ <tc:commandGroup id="headerInfo">
<tc:command omit="true" label="Info">
<tc:command omit="true" label="Theme: #{clientConfigController.localizedTheme}"/>
<tc:command omit="true" label="Locale: #{clientConfigController.localizedLocale}"/>
Added: myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/AjaxClientBehaviorRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/AjaxClientBehaviorRenderer.java?rev=1729565&view=auto
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/AjaxClientBehaviorRenderer.java (added)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/AjaxClientBehaviorRenderer.java Wed Feb 10 09:44:24 2016
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.tobago.renderkit.html;
+
+import org.apache.myfaces.tobago.internal.component.AbstractUICommand;
+import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
+import org.apache.myfaces.tobago.util.ComponentUtils;
+
+import javax.faces.component.behavior.AjaxBehavior;
+import javax.faces.component.behavior.ClientBehavior;
+import javax.faces.component.behavior.ClientBehaviorContext;
+import javax.faces.context.FacesContext;
+import javax.faces.render.ClientBehaviorRenderer;
+import java.util.Collection;
+
+public class AjaxClientBehaviorRenderer extends ClientBehaviorRenderer {
+
+ @Override
+ public String getScript(ClientBehaviorContext behaviorContext, ClientBehavior behavior) {
+
+ final AjaxBehavior ajaxBehavior = (AjaxBehavior) behavior;
+ final AbstractUICommand component = (AbstractUICommand) behaviorContext.getComponent();
+ final FacesContext facesContext = behaviorContext.getFacesContext();
+ final Collection<String> render = ajaxBehavior.getRender();
+
+ final Command command = new Command(
+ null,
+ component.isTransition(),
+ component.getTarget(),
+ RenderUtils.generateUrl(facesContext, component),
+ ComponentUtils.evaluateClientIds(facesContext, component, render.toArray(new String[render.size()])),
+ null,
+ null, // getConfirmation(command), // todo
+ null,
+ Popup.createPopup(component),
+ component.isOmit());
+
+ final CommandMap map = new CommandMap();
+ map.addCommand(behaviorContext.getEventName(), command);
+ return JsonUtils.encode(map);
+ }
+}
Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/Command.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/Command.java?rev=1729565&r1=1729564&r2=1729565&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/Command.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/Command.java Wed Feb 10 09:44:24 2016
@@ -69,6 +69,20 @@ public class Command {
this.omit = omit;
}
+ public Command(final FacesContext facesContext, final AbstractUICommand command, String[] ids) {
+ this(
+ null,
+ command.isTransition(),
+ command.getTarget(),
+ RenderUtils.generateUrl(facesContext, command),
+ ComponentUtils.evaluateClientIds(facesContext, command, ids),
+ null,
+ getConfirmation(command),
+ null,
+ Popup.createPopup(command),
+ command.isOmit());
+ }
+
public Command(final FacesContext facesContext, final AbstractUICommand command) {
this(
null,
Modified: myfaces/tobago/branches/tobago-3.0.x/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/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ButtonRenderer.java?rev=1729565&r1=1729564&r2=1729565&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ButtonRenderer.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ButtonRenderer.java Wed Feb 10 09:44:24 2016
@@ -43,8 +43,15 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.faces.component.UIComponent;
+import javax.faces.component.behavior.ClientBehavior;
+import javax.faces.component.behavior.ClientBehaviorBase;
+import javax.faces.component.behavior.ClientBehaviorContext;
+import javax.faces.component.behavior.ClientBehaviorHolder;
import javax.faces.context.FacesContext;
+import javax.faces.render.ClientBehaviorRenderer;
import java.io.IOException;
+import java.util.List;
+import java.util.Map;
public class ButtonRenderer extends CommandRendererBase {
@@ -72,9 +79,6 @@ public class ButtonRenderer extends Comm
writer.writeAttribute(HtmlAttributes.DISABLED, disabled);
if (!disabled) {
- final CommandMap map = new CommandMap(new Command(facesContext, button));
- writer.writeAttribute(DataAttributes.COMMANDS, JsonUtils.encode(map), true);
-
writer.writeAttribute(HtmlAttributes.HREF, "#", false);
if (label.getAccessKey() != null) {
@@ -88,6 +92,30 @@ public class ButtonRenderer extends Comm
writer.writeAttribute(HtmlAttributes.TABINDEX, tabIndex);
}
}
+
+ String commands = null;
+ final Map<String, List<ClientBehavior>> behaviors = ((ClientBehaviorHolder) component).getClientBehaviors();
+ for (Map.Entry<String, List<ClientBehavior>> behavior : behaviors.entrySet()) {
+ final String key = behavior.getKey();
+ final ClientBehaviorContext context
+ = ClientBehaviorContext.createClientBehaviorContext(facesContext, button, key, clientId, null);
+ for (ClientBehavior clientBehavior : behavior.getValue()) {
+ if (clientBehavior instanceof ClientBehaviorBase) {
+ final String type = ((ClientBehaviorBase) clientBehavior).getRendererType();
+ final ClientBehaviorRenderer clientBehaviorRenderer
+ = facesContext.getRenderKit().getClientBehaviorRenderer(type);
+ commands = clientBehaviorRenderer.getScript(context, clientBehavior);
+ } else {
+ LOG.warn("Ignoring: '{}'", clientBehavior);
+ }
+ }
+ }
+
+ if (commands == null) {
+ final CommandMap map = new CommandMap(new Command(facesContext, button));
+ commands = JsonUtils.encode(map);
+ }
+ writer.writeAttribute(DataAttributes.COMMANDS, commands, true);
}
writer.writeStyleAttribute(button.getStyle());
Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java?rev=1729565&r1=1729564&r2=1729565&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java Wed Feb 10 09:44:24 2016
@@ -318,7 +318,7 @@ public final class HtmlRendererUtils {
if (commandMap == null) {
commandMap = new CommandMap();
}
- commandMap.addCommand(columnEvent.getEvent(), new Command(facesContext, action, null));
+ commandMap.addCommand(columnEvent.getEvent(), new Command(facesContext, action, (String) null));
}
}
}
Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/FacesConfigGenerator.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/FacesConfigGenerator.java?rev=1729565&r1=1729564&r2=1729565&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/FacesConfigGenerator.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/FacesConfigGenerator.java Wed Feb 10 09:44:24 2016
@@ -120,6 +120,9 @@ public class FacesConfigGenerator extend
private static final String RENDER_KIT_CLASS = "render-kit-class";
private static final String RENDERER_TYPE = "renderer-type";
private static final String RENDERER_CLASS = "renderer-class";
+ private static final String CLIENT_BEHAVIOR_RENDERER = "client-behavior-renderer";
+ private static final String CLIENT_BEHAVIOR_RENDERER_TYPE = "client-behavior-renderer-type";
+ private static final String CLIENT_BEHAVIOR_RENDERER_CLASS = "client-behavior-renderer-class";
private static final Set<String> IGNORED_PROPERTIES = new HashSet<String>(Arrays.asList("binding"));
@@ -202,6 +205,16 @@ public class FacesConfigGenerator extend
renderKitClass.setText("org.apache.myfaces.tobago.renderkit.TobagoRenderKit");
renderKit.addContent(renderKitClass);
renderKit.addContent(newRenderer);
+
+ final org.jdom.Element clientBehaviorRender = new org.jdom.Element(CLIENT_BEHAVIOR_RENDERER, namespace);
+ final org.jdom.Element clientBehaviorType = new org.jdom.Element(CLIENT_BEHAVIOR_RENDERER_TYPE, namespace);
+ clientBehaviorType.setText("javax.faces.behavior.Ajax");
+ clientBehaviorRender.addContent(clientBehaviorType);
+ final org.jdom.Element clientBehaviorClass = new org.jdom.Element(CLIENT_BEHAVIOR_RENDERER_CLASS, namespace);
+ clientBehaviorClass.setText("org.apache.myfaces.tobago.renderkit.html.AjaxClientBehaviorRenderer");
+ clientBehaviorRender.addContent(clientBehaviorClass);
+ renderKit.addContent(clientBehaviorRender);
+
final int lastIndex = getIndexAfter(rootElement, CONVERTER, COMPONENT, FACTORY, APPLICATION);
rootElement.addContent(lastIndex, renderKit);
}