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 2013/04/10 15:40:09 UTC
svn commit: r1466484 - in /myfaces/tobago/trunk/tobago-theme:
tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/
tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/
tobago...
Author: lofwyr
Date: Wed Apr 10 13:40:08 2013
New Revision: 1466484
URL: http://svn.apache.org/r1466484
Log:
TOBAGO-1192: buttons and links rendering without javascript fragments
- simplify
Modified:
myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.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/CommandMap.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/CommandRendererHelper.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java?rev=1466484&r1=1466483&r2=1466484&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java Wed Apr 10 13:40:08 2013
@@ -20,7 +20,6 @@
package org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag;
import org.apache.myfaces.tobago.component.Attributes;
-import org.apache.myfaces.tobago.component.Facets;
import org.apache.myfaces.tobago.component.UIButton;
import org.apache.myfaces.tobago.config.Configurable;
import org.apache.myfaces.tobago.context.ResourceManagerUtils;
@@ -38,7 +37,6 @@ import org.apache.myfaces.tobago.renderk
import org.apache.myfaces.tobago.renderkit.html.HtmlButtonTypes;
import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
import org.apache.myfaces.tobago.renderkit.html.JsonUtils;
-import org.apache.myfaces.tobago.renderkit.html.Popup;
import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
import org.apache.myfaces.tobago.util.ComponentUtils;
@@ -47,7 +45,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.faces.component.UIComponent;
-import javax.faces.component.ValueHolder;
import javax.faces.context.FacesContext;
import java.io.IOException;
@@ -73,20 +70,7 @@ public class ButtonRenderer extends Comm
writer.writeAttribute(HtmlAttributes.DISABLED, disabled);
if (!disabled) {
- final ValueHolder confirmationFacet = (ValueHolder) component.getFacet(Facets.CONFIRMATION);
- final String confirmation = confirmationFacet != null ? "" + confirmationFacet.getValue() : null;
-
- final String url = RenderUtils.generateUrl(facesContext, button);
- final CommandMap map = new CommandMap();
- final String[] partialIds
- = HtmlRendererUtils.getComponentIdsAsList(facesContext, button, button.getRenderedPartially());
- final Popup popup = Popup.createPopup(button);
- final Command click = new Command(
- null, button.isTransition(), button.getTarget(), url, partialIds, null, confirmation, null, popup);
- if (button.getOnclick() != null) {
- click.setScript(button.getOnclick());
- }
- map.setClick(click);
+ final CommandMap map = new CommandMap(new Command(facesContext, button));
writer.writeAttribute(DataAttributes.COMMANDS, JsonUtils.encode(map), true);
writer.writeAttribute(HtmlAttributes.HREF, "#", false);
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java?rev=1466484&r1=1466483&r2=1466484&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java Wed Apr 10 13:40:08 2013
@@ -19,7 +19,6 @@
package org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag;
-import org.apache.myfaces.tobago.component.Facets;
import org.apache.myfaces.tobago.config.Configurable;
import org.apache.myfaces.tobago.context.ResourceManagerUtils;
import org.apache.myfaces.tobago.internal.component.AbstractUILink;
@@ -35,7 +34,6 @@ import org.apache.myfaces.tobago.renderk
import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
import org.apache.myfaces.tobago.renderkit.html.JsonUtils;
-import org.apache.myfaces.tobago.renderkit.html.Popup;
import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
@@ -43,7 +41,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.faces.component.UIComponent;
-import javax.faces.component.ValueHolder;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import java.io.IOException;
@@ -70,20 +67,7 @@ public class LinkRenderer extends Comman
writer.startElement(HtmlElements.A, link);
// writer.writeAttribute(HtmlAttributes.HREF, href, true); XXX
- final ValueHolder confirmationFacet = (ValueHolder) component.getFacet(Facets.CONFIRMATION);
- final String confirmation = confirmationFacet != null ? "" + confirmationFacet.getValue() : null;
-
- final String url = RenderUtils.generateUrl(facesContext, link);
- final CommandMap map = new CommandMap();
- final String[] partialIds
- = HtmlRendererUtils.getComponentIdsAsList(facesContext, link, link.getRenderedPartially());
- final Popup popup = Popup.createPopup(link);
- final Command click = new Command(
- null, link.isTransition(), link.getTarget(), url, partialIds, null, confirmation, null, popup);
- if (link.getOnclick() != null) {
- click.setScript(link.getOnclick());
- }
- map.setClick(click);
+ final CommandMap map = new CommandMap(new Command(facesContext, link));
writer.writeAttribute(DataAttributes.COMMANDS, JsonUtils.encode(map), true);
writer.writeAttribute(HtmlAttributes.HREF, "#", false);
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=1466484&r1=1466483&r2=1466484&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 Wed Apr 10 13:40:08 2013
@@ -21,14 +21,18 @@ package org.apache.myfaces.tobago.render
import org.apache.commons.lang.StringUtils;
import org.apache.myfaces.tobago.component.Attributes;
+import org.apache.myfaces.tobago.component.Facets;
import org.apache.myfaces.tobago.component.UICommand;
import org.apache.myfaces.tobago.component.UIForm;
import org.apache.myfaces.tobago.internal.component.AbstractUICommand;
+import org.apache.myfaces.tobago.internal.component.AbstractUICommandBase;
import org.apache.myfaces.tobago.internal.util.Deprecation;
import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
+import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
import org.apache.myfaces.tobago.util.ComponentUtils;
import javax.faces.component.UIComponent;
+import javax.faces.component.ValueHolder;
import javax.faces.context.FacesContext;
/**
@@ -50,11 +54,14 @@ public class Command {
private Integer delay;
private Popup popup;
/**
- * @deprecated
+ * @deprecated Script will not work when CSP is activated
*/
@Deprecated
private String script;
+ public Command() {
+ }
+
public Command(
String action, Boolean transition, String target, String url, String[] partially, String focus,
String confirmation, Integer delay, Popup popup) {
@@ -69,6 +76,22 @@ public class Command {
this.popup = popup;
}
+ public Command(FacesContext facesContext, AbstractUICommandBase command) {
+ this(
+ null,
+ command.isTransition(),
+ command.getTarget(),
+ RenderUtils.generateUrl(facesContext, command),
+ HtmlRendererUtils.getComponentIdsAsList(facesContext, command, command.getRenderedPartially()),
+ null,
+ getConfirmation(command),
+ null,
+ Popup.createPopup(command));
+ if (command.getOnclick() != null) {
+ script = command.getOnclick();
+ }
+ }
+
public Command(FacesContext facesContext, UIComponent facetComponent, String focusId) {
if (facetComponent instanceof UIForm && facetComponent.getChildCount() == 1) {
Deprecation.LOG.warn("Please don't use a form, but a command with immediate=true instead.");
@@ -107,6 +130,11 @@ public class Command {
}
}
+ private static String getConfirmation(AbstractUICommandBase command) {
+ final ValueHolder facet = (ValueHolder) command.getFacet(Facets.CONFIRMATION);
+ return facet != null ? "" + facet.getValue() : null;
+ }
+
public String getAction() {
return action;
}
@@ -180,14 +208,14 @@ public class Command {
}
/**
- * @deprecated
+ * @deprecated Script will not work when CSP is activated
*/
public String getScript() {
return script;
}
/**
- * @deprecated
+ * @deprecated Script will not work when CSP is activated
*/
@Deprecated
public void setScript(String script) {
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=1466484&r1=1466483&r2=1466484&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 Apr 10 13:40:08 2013
@@ -34,9 +34,19 @@ public class CommandMap {
private Command click;
private Map<String, Command> other;
+ /**
+ * Creates an empty command map, which may hold different command triggered by different keys.
+ */
public CommandMap() {
}
+ /**
+ * Creates a command map, which hold the given command triggered by "click".
+ */
+ public CommandMap(Command click) {
+ this.click = click;
+ }
+
public void setClick(Command click) {
this.click = click;
}
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/CommandRendererHelper.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/CommandRendererHelper.java?rev=1466484&r1=1466483&r2=1466484&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/CommandRendererHelper.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/CommandRendererHelper.java Wed Apr 10 13:40:08 2013
@@ -35,6 +35,10 @@ import javax.faces.component.ValueHolder
import javax.faces.context.FacesContext;
import java.util.Arrays;
+/**
+ * @deprecated since 2.0.0. Please use {@link org.apache.myfaces.tobago.renderkit.html.CommandMap}
+ */
+@Deprecated
public class CommandRendererHelper {
private static final Logger LOG = LoggerFactory.getLogger(CommandRendererHelper.class);
Modified: myfaces/tobago/trunk/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/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java?rev=1466484&r1=1466483&r2=1466484&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java Wed Apr 10 13:40:08 2013
@@ -625,7 +625,6 @@ public final class HtmlRendererUtils {
return strBuilder.toString();
}
-
public static void renderCommandFacet(UIComponent component, FacesContext facesContext,
TobagoResponseWriter writer) throws IOException {
renderCommandFacet(component, component.getClientId(facesContext), facesContext, writer);