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/09/14 15:37:34 UTC
svn commit: r1760727 - in /myfaces/tobago/trunk:
tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/
tobago-example/tobago-example-demo/src/main/webapp/content/20-component/080-sheet/30-event/
tobago-theme/tobago-th...
Author: lofwyr
Date: Wed Sep 14 15:37:34 2016
New Revision: 1760727
URL: http://svn.apache.org/viewvc?rev=1760727&view=rev
Log:
TOBAGO-1524: Use standard AJAX mechanism
* fix in sheet: tc:columnEvent without AJAX
Modified:
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SheetController.java
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/080-sheet/30-event/sheet-column-event.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/html/CommandMap.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SheetRenderer.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-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SheetController.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SheetController.java?rev=1760727&r1=1760726&r2=1760727&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SheetController.java (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SheetController.java Wed Sep 14 15:37:34 2016
@@ -44,6 +44,7 @@ public class SheetController implements
private SolarObject selectedSolarObject;
private boolean automaticLayout;
private List<Markup> markup;
+ private int columnEventSample;
public SheetController() {
solarList = SolarObject.getList();
@@ -104,4 +105,12 @@ public class SheetController implements
public void setMarkup(List<Markup> markup) {
this.markup = markup;
}
+
+ public void setColumnEventSample(int columnEventSample) {
+ this.columnEventSample = columnEventSample;
+ }
+
+ public int getColumnEventSample() {
+ return columnEventSample;
+ }
}
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/080-sheet/30-event/sheet-column-event.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/080-sheet/30-event/sheet-column-event.xhtml?rev=1760727&r1=1760726&r2=1760727&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/080-sheet/30-event/sheet-column-event.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/080-sheet/30-event/sheet-column-event.xhtml Wed Sep 14 15:37:34 2016
@@ -29,20 +29,37 @@
</p>
<tc:section label="Example">
+ Here are different examples:
+ <tc:selectOneRadio value="#{sheetController.columnEventSample}">
+ <tc:selectItem itemValue="0" itemLabel="on click with AJAX"/>
+ <tc:selectItem itemValue="1" itemLabel="on click with full request"/>
+ <tc:selectItem itemValue="2" itemLabel="on double click with full request"/>
+ <f:ajax render="example"/>
+ </tc:selectOneRadio>
<p>Select an object from the SolarObjects list.</p>
- <tc:segmentLayout medium="5;7">
+ <tc:segmentLayout id="example" medium="5;7">
<tc:box label="Solar Objects">
<tc:sheet id="s1" value="#{sheetController.solarList}" var="object" columns="1*">
<tc:style maxHeight="486px"/>
<tc:column label="#{overviewBundle.solarArrayName}" id="name">
<tc:out value="#{object.name}" id="t_name"/>
</tc:column>
- <tc:columnEvent event="click">
- <tc:command actionListener="#{sheetController.selectSolarObject}" immediate="true">
+ <tc:columnEvent id="sample0" rendered="#{sheetController.columnEventSample == 0}">
+ <tc:command actionListener="#{sheetController.selectSolarObject}" immediate="true" id="columnEventAjax">
<tc:resetInputActionListener/>
<f:ajax render=":::detail"/>
</tc:command>
</tc:columnEvent>
+ <tc:columnEvent id="sample1" rendered="#{sheetController.columnEventSample == 1}" event="click">
+ <tc:command actionListener="#{sheetController.selectSolarObject}" immediate="true" id="columnEventClick">
+ <tc:resetInputActionListener/>
+ </tc:command>
+ </tc:columnEvent>
+ <tc:columnEvent id="sample2" rendered="#{sheetController.columnEventSample == 2}" event="dblclick">
+ <tc:command actionListener="#{sheetController.selectSolarObject}" immediate="true" id="columnEventDblClick">
+ <tc:resetInputActionListener/>
+ </tc:command>
+ </tc:columnEvent>
</tc:sheet>
</tc:box>
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=1760727&r1=1760726&r2=1760727&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 Wed Sep 14 15:37:34 2016
@@ -40,6 +40,8 @@ import java.util.List;
public class AjaxClientBehaviorRenderer extends ClientBehaviorRenderer {
+ public static final String COMMAND_MAP = AjaxClientBehaviorRenderer.class.getName() + ".CommandMap";
+
@Override
public String getScript(ClientBehaviorContext behaviorContext, ClientBehavior behavior) {
@@ -91,8 +93,10 @@ public class AjaxClientBehaviorRenderer
final CommandMap map = new CommandMap();
map.addCommand(behaviorContext.getEventName(), command);
- return JsonUtils.encode(map);
+ facesContext.getAttributes().put(COMMAND_MAP, map);
+ // XXX the return value is a string, but we should use a CommandMap
+ return COMMAND_MAP;
}
@Override
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/CommandMap.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/CommandMap.java?rev=1760727&r1=1760726&r2=1760727&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/CommandMap.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/CommandMap.java Wed Sep 14 15:37:34 2016
@@ -76,4 +76,19 @@ public class CommandMap {
return null;
}
}
+
+ public void merge(final CommandMap commandMap) {
+ final Command click = commandMap.getClick();
+ if (click != null) {
+ setClick(click);
+ } else {
+ for (Map.Entry<String, Command> entry : commandMap.getOther().entrySet()) {
+ addCommand(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+
+ public boolean isEmpty() {
+ return click == null && other == null;
+ }
}
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SheetRenderer.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/SheetRenderer.java?rev=1760727&r1=1760726&r2=1760727&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SheetRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SheetRenderer.java Wed Sep 14 15:37:34 2016
@@ -37,7 +37,6 @@ import org.apache.myfaces.tobago.event.P
import org.apache.myfaces.tobago.internal.component.AbstractUIColumnBase;
import org.apache.myfaces.tobago.internal.component.AbstractUIColumnEvent;
import org.apache.myfaces.tobago.internal.component.AbstractUIColumnNode;
-import org.apache.myfaces.tobago.internal.component.AbstractUICommand;
import org.apache.myfaces.tobago.internal.component.AbstractUIData;
import org.apache.myfaces.tobago.internal.component.AbstractUIOut;
import org.apache.myfaces.tobago.internal.component.AbstractUISheet;
@@ -61,6 +60,8 @@ import org.apache.myfaces.tobago.renderk
import org.apache.myfaces.tobago.renderkit.css.Style;
import org.apache.myfaces.tobago.renderkit.css.TobagoClass;
import org.apache.myfaces.tobago.renderkit.html.Arias;
+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.HtmlButtonTypes;
@@ -1176,22 +1177,27 @@ public class SheetRenderer extends Rende
private static String renderSheetCommands(
final UISheet sheet, final FacesContext facesContext, final TobagoResponseWriter writer) throws IOException {
// TODO: TOBAGO-1572
- String commands = null;
+ final CommandMap commandMap = new CommandMap();
String rowActionId = null;
for (final UIComponent child : sheet.getChildren()) {
if (child instanceof UIColumnEvent && child.isRendered()) {
final UIColumnEvent columnEvent = (UIColumnEvent) child;
- if (columnEvent.getChildCount() > 0) {
- final UIComponent selectionChild = columnEvent.getChildren().get(0);
- if (selectionChild != null && selectionChild instanceof AbstractUICommand && selectionChild.isRendered()) {
- commands = RenderUtils.getBehaviorCommands(facesContext, (ClientBehaviorHolder) selectionChild);
- rowActionId = selectionChild.getId();
+ for (UIComponent uiCommand : columnEvent.getChildren()) {
+ if (uiCommand.isRendered()) {
+ if (uiCommand instanceof ClientBehaviorHolder) {
+ RenderUtils.addBehaviorCommands(facesContext, (ClientBehaviorHolder) uiCommand, commandMap);
+ rowActionId = uiCommand.getId();
+ }
+ final String event = columnEvent.getEvent();
+ if (event != null) {
+ commandMap.addCommand(event, new Command(facesContext, uiCommand, null));
+ }
}
}
}
}
- if (commands != null) {
- writer.writeAttribute(DataAttributes.ROW_ACTION, commands, true);
+ if (!commandMap.isEmpty()) {
+ writer.writeAttribute(DataAttributes.ROW_ACTION, JsonUtils.encode(commandMap), true);
}
return rowActionId;
}
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=1760727&r1=1760726&r2=1760727&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 Wed Sep 14 15:37:34 2016
@@ -26,6 +26,9 @@ import org.apache.myfaces.tobago.interna
import org.apache.myfaces.tobago.model.ExpandedState;
import org.apache.myfaces.tobago.model.SelectedState;
import org.apache.myfaces.tobago.model.TreePath;
+import org.apache.myfaces.tobago.renderkit.html.AjaxClientBehaviorRenderer;
+import org.apache.myfaces.tobago.renderkit.html.CommandMap;
+import org.apache.myfaces.tobago.renderkit.html.JsonUtils;
import org.apache.myfaces.tobago.util.ComponentUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -266,6 +269,14 @@ public final class RenderUtils {
}
public static String getBehaviorCommands(final FacesContext facesContext, final ClientBehaviorHolder holder) {
+
+ final CommandMap map = new CommandMap();
+ addBehaviorCommands(facesContext, holder, map);
+ return JsonUtils.encode(map);
+ }
+
+ public static void addBehaviorCommands(
+ final FacesContext facesContext, final ClientBehaviorHolder holder, final CommandMap commandMap) {
final Map<String, List<ClientBehavior>> behaviors = holder.getClientBehaviors();
for (Map.Entry<String, List<ClientBehavior>> behavior : behaviors.entrySet()) {
final String key = behavior.getKey();
@@ -276,13 +287,17 @@ public final class RenderUtils {
final String type = ((ClientBehaviorBase) clientBehavior).getRendererType();
final ClientBehaviorRenderer clientBehaviorRenderer
= facesContext.getRenderKit().getClientBehaviorRenderer(type);
- return clientBehaviorRenderer.getScript(context, clientBehavior);
+ final String marker = clientBehaviorRenderer.getScript(context, clientBehavior);
+ if (AjaxClientBehaviorRenderer.COMMAND_MAP.equals(marker)) {
+ commandMap.merge((CommandMap) facesContext.getAttributes().get(AjaxClientBehaviorRenderer.COMMAND_MAP));
+ } else {
+ LOG.error("Can't find prepared command map in faces context.");
+ }
} else {
LOG.warn("Ignoring: '{}'", clientBehavior);
}
}
}
- return null;
}
public static void decodeClientBehaviors(final FacesContext facesContext, final UIComponent component) {