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/06 06:56:20 UTC
svn commit: r1759367 - in
/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src:
main/java/org/apache/myfaces/tobago/renderkit/html/
main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/
main/resources/org/apache/myfaces/toba...
Author: lofwyr
Date: Tue Sep 6 06:56:20 2016
New Revision: 1759367
URL: http://svn.apache.org/viewvc?rev=1759367&view=rev
Log:
TOBAGO-1587: links doesn't support rightklick->newTab
TOBAGO-1557: Consolidate <tc:button>, <tc:link> and <tc:command>
* clean up: url is no longer needed in class Command (data attribute used for JS)
* fix "confirmation" before executing link (in progress)
Modified:
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/Command.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/JsonUtils.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/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/html/JsonUtilsUnitTest.java
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=1759367&r1=1759366&r2=1759367&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 Tue Sep 6 06:56:20 2016
@@ -21,6 +21,7 @@ package org.apache.myfaces.tobago.render
import org.apache.myfaces.tobago.internal.component.AbstractUICommand;
import org.apache.myfaces.tobago.internal.component.AbstractUIOperation;
+import org.apache.myfaces.tobago.internal.util.StringUtils;
import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
import org.apache.myfaces.tobago.util.ComponentUtils;
@@ -63,9 +64,11 @@ public class AjaxClientBehaviorRenderer
}
}
- final String url = (component instanceof AbstractUICommand)
- ? RenderUtils.generateUrl(facesContext, (AbstractUICommand) component)
- : null;
+ boolean omit = component instanceof AbstractUICommand &&
+ (((AbstractUICommand) component).isOmit()
+ // if it is a link, the default submit must not be called.
+ || StringUtils.isNotBlank(RenderUtils.generateUrl(facesContext, (AbstractUICommand) component)));
+
final String clientId = component.getClientId(facesContext);
String executeIds =
ComponentUtils.evaluateClientIds(facesContext, component, execute.toArray(new String[execute.size()]));
@@ -78,14 +81,13 @@ public class AjaxClientBehaviorRenderer
clientId,
(component instanceof AbstractUICommand) ? ((AbstractUICommand) component).isTransition() : null,
(component instanceof AbstractUICommand) ? ((AbstractUICommand) component).getTarget() : null,
- url,
executeIds,
ComponentUtils.evaluateClientIds(facesContext, component, render.toArray(new String[render.size()])),
null,
null, // getConfirmation(command), // todo
null,
collapse,
- (component instanceof AbstractUICommand) ? ((AbstractUICommand) component).isOmit() : null);
+ omit);
final CommandMap map = new CommandMap();
map.addCommand(behaviorContext.getEventName(), command);
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/Command.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/Command.java?rev=1759367&r1=1759366&r2=1759367&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/Command.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/Command.java Tue Sep 6 06:56:20 2016
@@ -24,7 +24,6 @@ import org.apache.myfaces.tobago.compone
import org.apache.myfaces.tobago.component.UIForm;
import org.apache.myfaces.tobago.internal.component.AbstractUICommand;
import org.apache.myfaces.tobago.internal.util.StringUtils;
-import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
import org.apache.myfaces.tobago.util.ComponentUtils;
import javax.faces.component.UIComponent;
@@ -44,7 +43,6 @@ public class Command {
private String action;
private Boolean transition;
private String target;
- private String url;
private String partially;
private String execute;
private String render;
@@ -58,13 +56,12 @@ public class Command {
}
public Command(
- final String action, final Boolean transition, final String target, final String url, final String execute,
+ final String action, final Boolean transition, final String target, final String execute,
final String render, final String focus, final String confirmation, final Integer delay,
final Collapse collapse, final Boolean omit) {
this.action = action;
this.transition = transition;
this.target = target;
- this.url = url;
setExecute(execute);
setRender(render);
this.focus = focus;
@@ -79,7 +76,6 @@ public class Command {
null,
command.isTransition(),
command.getTarget(),
- RenderUtils.generateUrl(facesContext, command),
null,
null,
null,
@@ -163,14 +159,6 @@ public class Command {
this.target = target;
}
- public String getUrl() {
- return url;
- }
-
- public void setUrl(final String url) {
- this.url = url;
- }
-
/**
* @deprecated use getExecute() getRender() instead
*/
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/JsonUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/JsonUtils.java?rev=1759367&r1=1759366&r2=1759367&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/JsonUtils.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/JsonUtils.java Tue Sep 6 06:56:20 2016
@@ -76,7 +76,7 @@ public class JsonUtils {
builder.append("]");
}
- static void encode(final StringBuilder builder, final String name, final Boolean value) {
+ private static void encode(final StringBuilder builder, final String name, final Boolean value) {
builder.append("\"");
builder.append(name);
builder.append("\":");
@@ -84,7 +84,7 @@ public class JsonUtils {
builder.append(",");
}
- static void encode(final StringBuilder builder, final String name, final Integer value) {
+ private static void encode(final StringBuilder builder, final String name, final Integer value) {
builder.append("\"");
builder.append(name);
builder.append("\":");
@@ -92,7 +92,7 @@ public class JsonUtils {
builder.append(",");
}
- static void encode(final StringBuilder builder, final String name, String value) {
+ private static void encode(final StringBuilder builder, final String name, String value) {
value = value.replaceAll("\\\"", "\\\\\\\""); // todo: optimize
builder.append("\"");
builder.append(name);
@@ -127,7 +127,7 @@ public class JsonUtils {
return builder.toString();
}
- static void encode(final StringBuilder builder, final String name, final Command command) {
+ private static void encode(final StringBuilder builder, final String name, final Command command) {
builder.append("\"");
builder.append(name);
builder.append("\":{");
@@ -145,10 +145,6 @@ public class JsonUtils {
if (target != null) {
encode(builder, "target", target);
}
- final String url = command.getUrl();
- if (url != null) {
- encode(builder, "url", url);
- }
final String partially = command.getPartially();
if (partially != null) {
encode(builder, "partially", partially);
@@ -179,7 +175,7 @@ public class JsonUtils {
}
final Boolean omit = command.getOmit();
if (omit != null && omit) { // false is the default, so encoding is needed.
- encode(builder, "omit", omit);
+ encode(builder, "omit", true);
}
if (builder.length() - initialLength > 0) {
@@ -190,7 +186,7 @@ public class JsonUtils {
builder.append("},");
}
- static void encode(final StringBuilder builder, final String name, final Collapse collapse) {
+ private static void encode(final StringBuilder builder, final String name, final Collapse collapse) {
builder.append("\"");
builder.append(name);
builder.append("\":{");
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=1759367&r1=1759366&r2=1759367&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 Tue Sep 6 06:56:20 2016
@@ -84,7 +84,7 @@ public abstract class CommandRendererBas
final String clientId = command.getClientId(facesContext);
final boolean disabled = command.isDisabled();
final LabelWithAccessKey label = new LabelWithAccessKey(command);
- final boolean link = command.getLink() != null && !disabled;
+ final boolean link = (command.getLink() != null || command.getResource() != null) && !disabled;
final String target = command.getTarget();
final TobagoResponseWriter writer = getResponseWriter(facesContext);
@@ -109,21 +109,18 @@ public abstract class CommandRendererBas
writer.writeAttribute(HtmlAttributes.DISABLED, disabled);
if (!disabled) {
- final String href;
+ if (link) {
+ final String href = RenderUtils.generateUrl(facesContext, command);
+ writer.writeAttribute(HtmlAttributes.HREF, href, false);
+ writer.writeAttribute(HtmlAttributes.TARGET, target, false);
+ }
+
String commands = RenderUtils.getBehaviorCommands(facesContext, command);
if (commands == null) { // old way
final CommandMap map = new CommandMap(new Command(facesContext, command));
commands = JsonUtils.encode(map);
- href = map.getClick().getUrl();
- } else {
- href = RenderUtils.generateUrl(facesContext, command);
- }
- if (link) {
- writer.writeAttribute(HtmlAttributes.HREF, href, false);
- writer.writeAttribute(HtmlAttributes.TARGET, target, false);
- } else {
- writer.writeAttribute(DataAttributes.COMMANDS, commands, true);
}
+ writer.writeAttribute(DataAttributes.COMMANDS, commands, true);
if (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.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.js?rev=1759367&r1=1759366&r2=1759367&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js Tue Sep 6 06:56:20 2016
@@ -564,15 +564,6 @@ var Tobago = {
});
event.preventDefault();
event.stopPropagation();
- } else if (commands.click.url) {
- if (commands.click.target) {
- window.open(commands.click.url, commands.click.target)
- } else {
- Tobago.navigateToUrl(commands.click.url);
- event.preventDefault();
- event.stopPropagation();
- return false;
- }
} else if (commands.click.script) { // XXX this case is deprecated.
// not allowed with Content Security Policy (CSP)
new Function('event' , commands.click.script)(event);
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/html/JsonUtilsUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/html/JsonUtilsUnitTest.java?rev=1759367&r1=1759366&r2=1759367&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/html/JsonUtilsUnitTest.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/html/JsonUtilsUnitTest.java Tue Sep 6 06:56:20 2016
@@ -47,7 +47,7 @@ public class JsonUtilsUnitTest extends A
@Test
public void click() {
final CommandMap map = new CommandMap();
- map.setClick(new Command(null, null, null, null, "", null, null, null, null, null, null));
+ map.setClick(new Command(null, null, null, "", null, null, null, null, null, null));
final String expected = "{'click':{}}".replaceAll("'", "\"");
Assert.assertEquals(expected, JsonUtils.encode(map));
}
@@ -55,7 +55,7 @@ public class JsonUtilsUnitTest extends A
@Test
public void change() {
final CommandMap map = new CommandMap();
- map.addCommand("change", new Command(null, null, null, null, null, null, null, null, null, null, null));
+ map.addCommand("change", new Command(null, null, null, null, null, null, null, null, null, null));
final String expected = "{'change':{}}".replaceAll("'", "\"");
Assert.assertEquals(expected, JsonUtils.encode(map));
}
@@ -63,8 +63,8 @@ public class JsonUtilsUnitTest extends A
@Test
public void two() {
final CommandMap map = new CommandMap();
- map.addCommand("click", new Command(null, null, "target", null, null, null, null, null, null, null, null));
- map.addCommand("change", new Command(null, null, null, null, null, null, null, null, null, null, null));
+ map.addCommand("click", new Command(null, null, "target", null, null, null, null, null, null, null));
+ map.addCommand("change", new Command(null, null, null, null, null, null, null, null, null, null));
final String expected = "{'click':{'target':'target'},'change':{}}".replaceAll("'", "\"");
Assert.assertEquals(expected, JsonUtils.encode(map));
}
@@ -72,7 +72,7 @@ public class JsonUtilsUnitTest extends A
@Test
public void transition() {
final CommandMap commandMap = new CommandMap();
- commandMap.setClick(new Command(null, false, null, null, null, null, null, null, null, null, null));
+ commandMap.setClick(new Command(null, false, null, null, null, null, null, null, null, null));
final String expected = "{'click':{'transition':false}}".replaceAll("'", "\"");
Assert.assertEquals(expected, JsonUtils.encode(commandMap));
}
@@ -88,7 +88,7 @@ public class JsonUtilsUnitTest extends A
map.setClick(new Command(
"ns:actionId",
false,
- "_blank", "http://www.apache.org/",
+ "_blank",
StringUtils.join(Arrays.asList("id1", "id2"), ' '),
StringUtils.join(Arrays.asList("id1", "id2"), ' '),
"id_focus",
@@ -99,7 +99,6 @@ public class JsonUtilsUnitTest extends A
+ "'action':'ns:actionId',"
+ "'transition':false,"
+ "'target':'_blank',"
- + "'url':'http://www.apache.org/',"
+ "'execute':'id1 id2',"
+ "'render':'id1 id2',"
+ "'collapse':{"