You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2016/07/24 11:52:24 UTC
svn commit: r1753914 - in /myfaces/tobago/trunk:
tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/
tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/
tobago-example/tobago-example-demo/src/mai...
Author: weber
Date: Sun Jul 24 11:52:23 2016
New Revision: 1753914
URL: http://svn.apache.org/viewvc?rev=1753914&view=rev
Log:
TOBAGO-1574 - AJAX not working from change-facet-command
Modified:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUICommand.java
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/PartialReloadController.java
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/50-partial/partial.xhtml
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/AjaxClientBehaviorRenderer.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUICommand.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUICommand.java?rev=1753914&r1=1753913&r2=1753914&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUICommand.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUICommand.java Sun Jul 24 11:52:23 2016
@@ -51,7 +51,7 @@ public abstract class AbstractUICommand
private static final Logger LOG = LoggerFactory.getLogger(AbstractUICommand.class);
// todo generate
- private static final Collection<String> EVENT_NAMES = Arrays.asList("click");
+ private static final Collection<String> EVENT_NAMES = Arrays.asList("click", "change");
enum PropertyKeys {
disabled,
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/PartialReloadController.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/PartialReloadController.java?rev=1753914&r1=1753913&r2=1753914&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/PartialReloadController.java (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/PartialReloadController.java Sun Jul 24 11:52:23 2016
@@ -86,21 +86,21 @@ public class PartialReloadController {
if (navigateAction == null) {
return logAndNavigate(null);
} else if ("left".equals(navigateAction)) {
-// AjaxUtils.addAjaxComponent(facesContext, "page:left");
+ facesContext.getPartialViewContext().getRenderIds().add("page:mainForm:left");
navigateAction = null;
return logAndNavigate(null);
} else if ("right".equals(navigateAction)) {
-// AjaxUtils.addAjaxComponent(facesContext, "page:right");
+ facesContext.getPartialViewContext().getRenderIds().add("page:mainForm:right");
navigateAction = null;
return logAndNavigate(null);
} else if ("both".equals(navigateAction)) {
-// AjaxUtils.addAjaxComponent(facesContext, "page:left");
-// AjaxUtils.addAjaxComponent(facesContext, "page:right");
+ facesContext.getPartialViewContext().getRenderIds().add("page:mainForm:left");
+ facesContext.getPartialViewContext().getRenderIds().add("page:mainForm:right");
navigateAction = null;
return logAndNavigate(null);
} else if ("parent".equals(navigateAction)) {
navigateAction = null;
-// AjaxUtils.addAjaxComponent(facesContext, "page:parent");
+ facesContext.getPartialViewContext().getRenderIds().add("page:mainForm:parent");
return logAndNavigate(null);
} else if ("prev".equals(navigateAction)) {
navigateAction = null;
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/50-partial/partial.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/50-partial/partial.xhtml?rev=1753914&r1=1753913&r2=1753914&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/50-partial/partial.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/50-partial/partial.xhtml Sun Jul 24 11:52:23 2016
@@ -123,7 +123,8 @@
<tc:selectOneChoice fieldId="navSelect" value="#{partialReloadController.navigateAction}" label="On Change">
<f:facet name="change">
- <tc:command action="#{partialReloadController.navigateAction}" renderedPartially="navTest :page:header:headerInfo"/>
+ <tc:command action="#{partialReloadController.navigateAction}"
+ renderedPartially="navTest :page:header:headerInfo"/>
</f:facet>
<f:selectItem itemLabel="Select action" itemValue=""/>
<f:selectItem itemLabel="Reload left" itemValue="left"/>
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/AjaxClientBehaviorRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/AjaxClientBehaviorRenderer.java?rev=1753914&r1=1753913&r2=1753914&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/AjaxClientBehaviorRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/AjaxClientBehaviorRenderer.java Sun Jul 24 11:52:23 2016
@@ -31,6 +31,7 @@ import javax.faces.component.behavior.Aj
import javax.faces.component.behavior.ClientBehavior;
import javax.faces.component.behavior.ClientBehaviorContext;
import javax.faces.context.FacesContext;
+import javax.faces.event.ActionEvent;
import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.event.PhaseId;
import javax.faces.render.ClientBehaviorRenderer;
@@ -51,44 +52,38 @@ public class AjaxClientBehaviorRenderer
//// TBD: is this nice? May be implemented with a JSF behaviour?
final Collapse collapse = createCollapsible(facesContext, uiComponent);
+ final UIComponent component;
if (uiComponent instanceof AbstractUICommand) {
- final AbstractUICommand component = (AbstractUICommand) uiComponent;
-
- final Command command = new Command(
- null,
- component.isTransition(),
- component.getTarget(),
- RenderUtils.generateUrl(facesContext, component),
- ComponentUtils.evaluateClientIds(facesContext, component, execute.toArray(new String[execute.size()])),
- ComponentUtils.evaluateClientIds(facesContext, component, render.toArray(new String[render.size()])),
- null,
- null, // getConfirmation(command), // todo
- null,
- collapse,
- component.isOmit());
-
- final CommandMap map = new CommandMap();
- map.addCommand(behaviorContext.getEventName(), command);
- return JsonUtils.encode(map);
+ component = uiComponent;
} else {
- // todo
- final Command command = new Command(
- null,
- null,
- null,
- null,
- ComponentUtils.evaluateClientIds(facesContext, uiComponent, execute.toArray(new String[execute.size()])),
- ComponentUtils.evaluateClientIds(facesContext, uiComponent, render.toArray(new String[render.size()])),
- null,
- null,
- null,
- collapse,
- null);
-
- final CommandMap map = new CommandMap();
- map.addCommand(behaviorContext.getEventName(), command);
- return JsonUtils.encode(map);
+ final UIComponent facetComponent = uiComponent.getFacet(behaviorContext.getEventName());
+ if (facetComponent instanceof AbstractUICommand) {
+ component = facetComponent;
+ } else {
+ component = uiComponent;
+ }
}
+
+ final String url = (component instanceof AbstractUICommand)
+ ? RenderUtils.generateUrl(facesContext, (AbstractUICommand) component)
+ : null;
+ final Command command = new Command(
+ component.getClientId(facesContext),
+ (component instanceof AbstractUICommand) ? ((AbstractUICommand) component).isTransition() : null,
+ (component instanceof AbstractUICommand) ? ((AbstractUICommand) component).getTarget() : null,
+ url,
+ ComponentUtils.evaluateClientIds(facesContext, component, execute.toArray(new String[execute.size()])),
+ ComponentUtils.evaluateClientIds(facesContext, component, render.toArray(new String[render.size()])),
+ null,
+ null, // getConfirmation(command), // todo
+ null,
+ collapse,
+ (component instanceof AbstractUICommand) ? ((AbstractUICommand)component).isOmit() : null);
+
+ final CommandMap map = new CommandMap();
+ map.addCommand(behaviorContext.getEventName(), command);
+ return JsonUtils.encode(map);
+
}
@Override
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java?rev=1753914&r1=1753913&r2=1753914&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java Sun Jul 24 11:52:23 2016
@@ -42,9 +42,12 @@ import javax.faces.component.behavior.Cl
import javax.faces.component.behavior.ClientBehaviorHolder;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
+import javax.faces.event.ActionEvent;
import javax.faces.render.ClientBehaviorRenderer;
import java.io.IOException;
import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -258,12 +261,39 @@ public final class RenderUtils {
return url;
}
- public static String getBehaviorCommands(final FacesContext facesContext, final ClientBehaviorHolder button) {
- final Map<String, List<ClientBehavior>> behaviors = button.getClientBehaviors();
+ public static String getBehaviorCommands(final FacesContext facesContext, final ClientBehaviorHolder holder) {
+ final Map<String, List<ClientBehavior>> behaviors;
+ if (holder instanceof AbstractUICommand) {
+ behaviors = holder.getClientBehaviors();
+ } else {
+ // search for clientBehaviorHolder in facets
+ behaviors = new HashMap<String, List<ClientBehavior>>();
+ for (Map.Entry<String, UIComponent> facetEntry : ((UIComponent) holder).getFacets().entrySet()) {
+ if (facetEntry.getValue() instanceof ClientBehaviorHolder) {
+ final ClientBehaviorHolder behaviorHolder = (ClientBehaviorHolder) facetEntry.getValue();
+ final Map<String, List<ClientBehavior>> behaviorsMap = behaviorHolder.getClientBehaviors();
+ final List<ClientBehavior> clientBehaviors = new ArrayList<ClientBehavior>();
+ final String facetName = facetEntry.getKey();
+ if (behaviorsMap.get(facetName) != null) {
+ clientBehaviors.addAll(behaviorsMap.get(facetName));
+ }
+ // if facet name != "click" and the behaviorCommands are added as default they must moved to the correct map
+ if (clientBehaviors.isEmpty() && behaviorsMap.get("click") != null) {
+ final List<ClientBehavior> clickBehaviors = behaviorsMap.get("click");
+ for (ClientBehavior behavior : clickBehaviors) {
+ behaviorHolder.addClientBehavior(facetName, behavior);
+ clientBehaviors.add(behavior);
+ }
+ clickBehaviors.clear();
+ }
+ behaviors.put(facetName, clientBehaviors);
+ }
+ }
+ }
for (Map.Entry<String, List<ClientBehavior>> behavior : behaviors.entrySet()) {
final String key = behavior.getKey();
final ClientBehaviorContext context = ClientBehaviorContext.createClientBehaviorContext(
- facesContext, (UIComponent) button, key, ((UIComponent) button).getClientId(facesContext), null);
+ facesContext, (UIComponent) holder, key, ((UIComponent) holder).getClientId(facesContext), null);
for (ClientBehavior clientBehavior : behavior.getValue()) {
if (clientBehavior instanceof ClientBehaviorBase) {
final String type = ((ClientBehaviorBase) clientBehavior).getRendererType();
@@ -281,20 +311,30 @@ public final class RenderUtils {
public static void decodeClientBehaviors(final FacesContext facesContext, final UIComponent component) {
if (component instanceof ClientBehaviorHolder) {
- final ClientBehaviorHolder clientBehaviorHolder = (ClientBehaviorHolder) component;
+ final Map<String, String> paramMap = facesContext.getExternalContext().getRequestParameterMap();
+ final String behaviorEventName = paramMap.get("javax.faces.behavior.event");
+ if (behaviorEventName == null) {
+ return;
+ }
+
+ final ClientBehaviorHolder clientBehaviorHolder;
+ if ("click".equals(behaviorEventName)) {
+ clientBehaviorHolder = (ClientBehaviorHolder) component;
+ } else if (component.getFacet(behaviorEventName) instanceof ClientBehaviorHolder) {
+ clientBehaviorHolder = (ClientBehaviorHolder) component.getFacet(behaviorEventName);
+ } else {
+ return;
+ }
final Map<String, List<ClientBehavior>> clientBehaviors = clientBehaviorHolder.getClientBehaviors();
if (clientBehaviors != null && !clientBehaviors.isEmpty()) {
- final Map<String, String> paramMap = facesContext.getExternalContext().getRequestParameterMap();
- final String behaviorEventName = paramMap.get("javax.faces.behavior.event");
- if (behaviorEventName != null) {
- final List<ClientBehavior> clientBehaviorList = clientBehaviors.get(behaviorEventName);
- if (clientBehaviorList != null && !clientBehaviorList.isEmpty()) {
- final String clientId = paramMap.get("javax.faces.source");
- if (component.getClientId(facesContext).equals(clientId)) {
- for (ClientBehavior clientBehavior : clientBehaviorList) {
- clientBehavior.decode(facesContext, component);
- }
+ List<ClientBehavior> clientBehaviorList = clientBehaviors.get(behaviorEventName);
+ if (clientBehaviorList != null && !clientBehaviorList.isEmpty()) {
+ final String clientId = paramMap.get("javax.faces.source");
+ if (component.getClientId(facesContext).equals(clientId)) {
+ for (ClientBehavior clientBehavior : clientBehaviorList) {
+ clientBehavior.decode(facesContext, component);
}
+ ((UIComponent) clientBehaviorHolder).queueEvent(new ActionEvent((UIComponent) clientBehaviorHolder));
}
}
}