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 2014/08/29 18:00:50 UTC
svn commit: r1621332 - in /myfaces/tobago/trunk:
tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/declaration/
tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/
tobago-core/src/main/java/org/apache/myfaces/tobago/uti...
Author: lofwyr
Date: Fri Aug 29 16:00:50 2014
New Revision: 1621332
URL: http://svn.apache.org/r1621332
Log:
better documentation of renderedPartially
Modified:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/declaration/HasRenderedPartially.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/FindComponentUtils.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/02-sheet/sheet.xhtml
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/50-partial/partial.xhtml
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/header.xhtml
myfaces/tobago/trunk/tobago-extension/tobago-deprecation/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/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/SheetRenderer.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/declaration/HasRenderedPartially.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/declaration/HasRenderedPartially.java?rev=1621332&r1=1621331&r2=1621332&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/declaration/HasRenderedPartially.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/declaration/HasRenderedPartially.java Fri Aug 29 16:00:50 2014
@@ -26,7 +26,7 @@ import org.apache.myfaces.tobago.apt.ann
public interface HasRenderedPartially {
/**
* <p>
- * Indicate the partially rendered Components in a case of a submit.
+ * Indicate the partially rendered components in a case of a submit.
* </p>
* <p>
* The search depends on the number of prefixed colons in the relativeId:
@@ -46,6 +46,11 @@ public interface HasRenderedPartially {
* <p>
* If a literal is specified: to use more than one identifier the identifiers must be space delimited.
* </p>
+ * <p>
+ * Using this in a UISheet component this list indicates components to update when calling
+ * internal AJAX requests like sort or paging commands.
+ * Don't forget to add the sheets id in that case, if needed.
+ * </p>
*/
@TagAttribute
@UIComponentTagAttribute(type = "java.lang.String[]")
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/FindComponentUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/FindComponentUtils.java?rev=1621332&r1=1621331&r2=1621332&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/FindComponentUtils.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/FindComponentUtils.java Fri Aug 29 16:00:50 2014
@@ -19,49 +19,26 @@
package org.apache.myfaces.tobago.internal.util;
-import javax.faces.component.NamingContainer;
+import org.apache.myfaces.tobago.util.ComponentUtils;
+
import javax.faces.component.UIComponent;
-import javax.faces.component.UINamingContainer;
-import javax.faces.context.FacesContext;
-// Will be normally called via ComponentUtils.
+/**
+ * @deprecated Since 2.0.3
+ */
public final class FindComponentUtils {
+ /**
+ * @deprecated Since 2.0.3
+ */
private FindComponentUtils() {
}
+ /**
+ * @deprecated Since 2.0.3, please use {@link org.apache.myfaces.tobago.util.ComponentUtils#findComponent(
+ * javax.faces.component.UIComponent, String)}
+ */
public static UIComponent findComponent(UIComponent from, String relativeId) {
- final int idLength = relativeId.length();
- if (idLength > 0 && relativeId.charAt(0) == '@') {
- if (relativeId.equals("@this")) {
- return from;
- }
- }
-
- // Figure out how many colons
- int colonCount = 0;
- while (colonCount < idLength) {
- if (relativeId.charAt(colonCount) != UINamingContainer.getSeparatorChar(FacesContext.getCurrentInstance())) {
- break;
- }
- colonCount++;
- }
-
- // colonCount == 0: fully relative
- // colonCount == 1: absolute (still normal findComponent syntax)
- // colonCount > 1: for each extra colon after 1, go up a naming container
- // (to the view root, if naming containers run out)
- if (colonCount > 1) {
- relativeId = relativeId.substring(colonCount);
- for (int j = 1; j < colonCount; j++) {
- while (from.getParent() != null) {
- from = from.getParent();
- if (from instanceof NamingContainer) {
- break;
- }
- }
- }
- }
- return from.findComponent(relativeId);
+ return ComponentUtils.findComponent(from, relativeId);
}
}
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java?rev=1621332&r1=1621331&r2=1621332&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java Fri Aug 29 16:00:50 2014
@@ -23,6 +23,7 @@ import org.apache.myfaces.tobago.compone
import org.apache.myfaces.tobago.component.Facets;
import org.apache.myfaces.tobago.component.RendererTypes;
import org.apache.myfaces.tobago.component.SupportsMarkup;
+import org.apache.myfaces.tobago.component.UISheet;
import org.apache.myfaces.tobago.context.Markup;
import org.apache.myfaces.tobago.context.TransientStateHolder;
import org.apache.myfaces.tobago.event.AbstractPopupActionListener;
@@ -32,7 +33,6 @@ import org.apache.myfaces.tobago.interna
import org.apache.myfaces.tobago.internal.component.AbstractUIPopup;
import org.apache.myfaces.tobago.internal.util.ArrayUtils;
import org.apache.myfaces.tobago.internal.util.Deprecation;
-import org.apache.myfaces.tobago.internal.util.FindComponentUtils;
import org.apache.myfaces.tobago.internal.util.ObjectUtils;
import org.apache.myfaces.tobago.internal.util.StringUtils;
import org.apache.myfaces.tobago.renderkit.RendererBase;
@@ -50,6 +50,7 @@ import javax.faces.component.UICommand;
import javax.faces.component.UIComponent;
import javax.faces.component.UIGraphic;
import javax.faces.component.UIInput;
+import javax.faces.component.UINamingContainer;
import javax.faces.component.UIOutput;
import javax.faces.component.UIParameter;
import javax.faces.component.UISelectMany;
@@ -881,19 +882,98 @@ public final class ComponentUtils {
}
/**
- * The search depends on the number of colons in the relativeId:
+ * <p>
+ * The search depends on the number of prefixed colons in the relativeId:
* <dl>
- * <dd>colonCount == 0</dd>
+ * <dd>number of prefixed colons == 0</dd>
* <dt>fully relative</dt>
- * <dd>colonCount == 1</dd>
+ * <dd>number of prefixed colons == 1</dd>
* <dt>absolute (still normal findComponent syntax)</dt>
- * <dd>colonCount > 1</dd>
- * <dt>for each extra colon after 1, go up a naming container</dt>
+ * <dd>number of prefixed colons == 2</dd>
+ * <dt>search in the current naming container (same as 0 colons)</dt>
+ * <dd>number of prefixed colons == 3</dd>
+ * <dt>search in the parent naming container of the current naming container</dt>
+ * <dd>number of prefixed colons > 3</dd>
+ * <dt>go to the next parent naming container for each additional colon</dt>
* </dl>
- * (to the view root, if naming containers run out)
+ * </p>
+ * <p>
+ * If a literal is specified: to use more than one identifier the identifiers must be space delimited.
+ * </p>
*/
public static UIComponent findComponent(final UIComponent from, final String relativeId) {
- return FindComponentUtils.findComponent(from, relativeId);
+ UIComponent from1 = from;
+ String relativeId1 = relativeId;
+ final int idLength = relativeId1.length();
+ if (idLength > 0 && relativeId1.charAt(0) == '@') {
+ if (relativeId1.equals("@this")) {
+ return from1;
+ }
+ }
+
+ // Figure out how many colons
+ int colonCount = 0;
+ while (colonCount < idLength) {
+ if (relativeId1.charAt(colonCount) != UINamingContainer.getSeparatorChar(FacesContext.getCurrentInstance())) {
+ break;
+ }
+ colonCount++;
+ }
+
+ // colonCount == 0: fully relative
+ // colonCount == 1: absolute (still normal findComponent syntax)
+ // colonCount > 1: for each extra colon after 1, go up a naming container
+ // (to the view root, if naming containers run out)
+ if (colonCount > 1) {
+ relativeId1 = relativeId1.substring(colonCount);
+ for (int j = 1; j < colonCount; j++) {
+ while (from1.getParent() != null) {
+ from1 = from1.getParent();
+ if (from1 instanceof NamingContainer) {
+ break;
+ }
+ }
+ }
+ }
+ return from1.findComponent(relativeId1);
+ }
+
+ /**
+ * Resolves the real clientIds.
+ */
+ public static String[] evaluateClientIds(
+ final FacesContext context, final UIComponent component, final String[] componentId) {
+ final List<String> result = new ArrayList<String>(componentId.length);
+ for (final String id : componentId) {
+ if (!StringUtils.isBlank(id)) {
+ final String clientId = evaluateClientId(context, component, id);
+ if (clientId != null) {
+ result.add(clientId);
+ }
+ }
+ }
+ return (String[]) result.toArray(new String[result.size()]);
+ }
+
+ /**
+ * Resolves the real clientId.
+ */
+ public static String evaluateClientId(
+ final FacesContext context, final UIComponent component, final String componentId) {
+ final UIComponent partiallyComponent = ComponentUtils.findComponent(component, componentId);
+ if (partiallyComponent != null) {
+ final String clientId = partiallyComponent.getClientId(context);
+ if (partiallyComponent instanceof UISheet) {
+ final int rowIndex = ((UISheet) partiallyComponent).getRowIndex();
+ if (rowIndex >= 0 && clientId.endsWith(Integer.toString(rowIndex))) {
+ return clientId.substring(0, clientId.lastIndexOf(UINamingContainer.getSeparatorChar(context)));
+ }
+ }
+ return clientId;
+ }
+ LOG.error("No component found for id='" + componentId + "', "
+ + "search base component is '" + component.getClientId(context) + "'");
+ return null;
}
public static String[] splitList(final String renderers) {
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/02-sheet/sheet.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/02-sheet/sheet.xhtml?rev=1621332&r1=1621331&r2=1621332&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/02-sheet/sheet.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/02-sheet/sheet.xhtml Fri Aug 29 16:00:50 2014
@@ -139,7 +139,8 @@
directLinkCount="#{overviewController.sheetConfig.sheetDirectLinkCount}"
stateChangeListener="#{demo.stateChangeListener}"
sortActionListener="#{overviewController.sheetSorter}"
- selectable="#{overviewController.sheetConfig.selectable}">
+ selectable="#{overviewController.sheetConfig.selectable}"
+ renderedPartially=":page:header:headerInfo sheet">
<!--
<f:facet name="reload">
<tc:reload frequency="2000" />
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/50-partial/partial.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/50-partial/partial.xhtml?rev=1621332&r1=1621331&r2=1621332&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/50-partial/partial.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/50-partial/partial.xhtml Fri Aug 29 16:00:50 2014
@@ -87,31 +87,31 @@
</f:facet>
<tc:button label="Reload left" tip="Reload left side box"
- action="#{partialReloadController.reload}" renderedPartially="left"/>
+ action="#{partialReloadController.reload}" renderedPartially="left :page:header:headerInfo"/>
<tc:button label="Reload right" tip="Reload right side box"
- action="#{partialReloadController.reload}" renderedPartially="right"/>
+ action="#{partialReloadController.reload}" renderedPartially="right :page:header:headerInfo"/>
<tc:button label="Reload both" tip="Reload both boxes"
- action="#{partialReloadController.reload}" renderedPartially="left right">
+ action="#{partialReloadController.reload}" renderedPartially="left right :page:header:headerInfo">
<tc:gridLayoutConstraint columnSpan="2"/>
</tc:button>
<tc:button label="Reload full panel"
tip="Reload the full area inside the outer box"
- action="#{partialReloadController.reload}" renderedPartially="parent">
+ action="#{partialReloadController.reload}" renderedPartially="parent :page:header:headerInfo">
<tc:gridLayoutConstraint columnSpan="2"/>
</tc:button>
<tc:button label="Reload both (wait 3 s)"
tip="Reload both boxes, but the server has a delay of 3 seconds"
- action="#{partialReloadController.waitAndReload3}" renderedPartially="left right">
+ action="#{partialReloadController.waitAndReload3}" renderedPartially="left right :page:header:headerInfo">
<tc:gridLayoutConstraint columnSpan="2"/>
</tc:button>
- <tc:button label="Reload both (wait 7 s)"
+ <tc:button label="Reload both (wait 7 s, timeout)"
tip="Reload both boxes, but the server has a delay of 7 seconds, this is more than the default timeout for AJAX"
- action="#{partialReloadController.waitAndReload7}" renderedPartially="left right">
+ action="#{partialReloadController.waitAndReload7}" renderedPartially="left right :page:header:headerInfo">
<tc:gridLayoutConstraint columnSpan="2"/>
</tc:button>
@@ -120,8 +120,7 @@
<tx:selectOneChoice fieldId="navSelect" value="#{partialReloadController.navigateAction}" label="On Change">
<f:facet name="change">
- <!-- XXX value="fixme" should be empty, but it doesn't work with an empty string -->
- <tc:command action="#{partialReloadController.navigateAction}" renderedPartially="navTest"/>
+ <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"/>
@@ -135,10 +134,10 @@
</tc:panel>
<tc:button label="Error left" tip="Reload left side box, but an exception occures"
- action="#{partialReloadController.error}" renderedPartially="left"/>
+ action="#{partialReloadController.error}" renderedPartially="left :page:header:headerInfo"/>
<tc:button label="Error right" tip="Reload right side box, but an exception occures"
- action="#{partialReloadController.error}" renderedPartially="right"/>
+ action="#{partialReloadController.error}" renderedPartially="right :page:header:headerInfo"/>
</tc:panel>
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/header.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/header.xhtml?rev=1621332&r1=1621331&r2=1621332&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/header.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/header.xhtml Fri Aug 29 16:00:50 2014
@@ -22,7 +22,7 @@
xmlns:tc="http://myfaces.apache.org/tobago/component">
<tc:panel>
<f:facet name="layout">
- <tc:gridLayout columns="150px;*;200px"/>
+ <tc:gridLayout columns="150px;*;400px"/>
</f:facet>
<tc:link action="#{navigationState.gotoFirst}" immediate="true" image="image/tobago_head.gif"/>
@@ -34,15 +34,16 @@
<tc:out value="The demo is in progress." markup="strong"/>
</tc:panel>
- <tc:panel>
+ <tc:panel id="headerInfo">
<f:facet name="layout">
- <tc:gridLayout rows="15px;15px;15px;15px;15px"/>
+ <tc:gridLayout rows="15px;15px;15px" columns="*;*"/>
</f:facet>
<tc:out value="Theme: #{clientConfigController.localizedTheme}"/>
<tc:out value="Locale: #{clientConfigController.localizedLocale}"/>
<tc:out value="VDL: Facelets" tip="View Description Language"/>
<tc:out value="Project Stage: #{tobagoContext.tobagoConfig.projectStage}"/>
<tc:out value="CSP mode: #{tobagoContext.tobagoConfig.contentSecurityPolicy.mode}"/>
+ <tc:out value="Requests: #{activityList.values[0].jsfRequest} / AJAX: #{activityList.values[0].ajaxRequest}"/>
</tc:panel>
</tc:panel>
</f:subview>
Modified: myfaces/tobago/trunk/tobago-extension/tobago-deprecation/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/CommandRendererHelper.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-extension/tobago-deprecation/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/CommandRendererHelper.java?rev=1621332&r1=1621331&r2=1621332&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-extension/tobago-deprecation/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/CommandRendererHelper.java (original)
+++ myfaces/tobago/trunk/tobago-extension/tobago-deprecation/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/CommandRendererHelper.java Fri Aug 29 16:00:50 2014
@@ -99,7 +99,7 @@ public class CommandRendererHelper {
+ Arrays.toString(componentIds));
}
onclick = "Tobago.Popup.openWithAction(this, '"
- + HtmlRendererUtils.getComponentId(facesContext, command, componentIds[0]) + "', '" + clientId + "');";
+ + ComponentUtils.evaluateClientId(facesContext, command, componentIds[0]) + "', '" + clientId + "');";
} else {
onclick = "Tobago.reloadComponent(this, '"
+ HtmlRendererUtils.getComponentIds(facesContext, command, componentIds) + "','" + clientId + "', {});";
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=1621332&r1=1621331&r2=1621332&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 Fri Aug 29 16:00:50 2014
@@ -26,7 +26,6 @@ import org.apache.myfaces.tobago.compone
import org.apache.myfaces.tobago.internal.component.AbstractUICommand;
import org.apache.myfaces.tobago.internal.util.Deprecation;
import org.apache.myfaces.tobago.internal.util.StringUtils;
-import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
import org.apache.myfaces.tobago.util.ComponentUtils;
@@ -82,7 +81,7 @@ public class Command {
command.isTransition(),
command.getTarget(),
RenderUtils.generateUrl(facesContext, command),
- HtmlRendererUtils.getComponentIdsAsList(facesContext, command, command.getRenderedPartially()),
+ ComponentUtils.evaluateClientIds(facesContext, command, command.getRenderedPartially()),
null,
getConfirmation(command),
null,
@@ -109,7 +108,7 @@ public class Command {
}
if (facetComponent instanceof AbstractUICommand
&& ((AbstractUICommand) facetComponent).getRenderedPartially().length > 0) {
- this.partially = HtmlRendererUtils.getComponentIdsAsList(
+ this.partially = ComponentUtils.evaluateClientIds(
facesContext, facetComponent, ((UICommand) facetComponent).getRenderedPartially());
} else {
String facetAction = (String) facetComponent.getAttributes().get(Attributes.ONCLICK);
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=1621332&r1=1621331&r2=1621332&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 Fri Aug 29 16:00:50 2014
@@ -31,7 +31,13 @@ public class JsonUtils {
private static void encode(final StringBuilder builder, final String name, final String[] value) {
builder.append("\"");
builder.append(name);
- builder.append("\":[");
+ builder.append("\":");
+ encode(builder, value);
+ builder.append(",");
+ }
+
+ public static void encode(StringBuilder builder, String[] value) {
+ builder.append("[");
boolean colon = false;
for (final String item : value) {
if (colon) {
@@ -42,7 +48,7 @@ public class JsonUtils {
builder.append("\"");
colon = true;
}
- builder.append("],");
+ builder.append("]");
}
static void encode(final StringBuilder builder, final String name, final Boolean value) {
@@ -62,7 +68,7 @@ public class JsonUtils {
}
static void encode(final StringBuilder builder, final String name, String value) {
- value = value.replaceAll("\\\"", "\\\\\\\"");
+ value = value.replaceAll("\\\"", "\\\\\\\""); // todo: optimize
builder.append("\"");
builder.append(name);
builder.append("\":\"");
@@ -200,4 +206,13 @@ public class JsonUtils {
builder.append("}");
return builder.toString();
}
+
+ public static String encode(final String[] strings) {
+ if (strings == null) {
+ return null;
+ }
+ final StringBuilder builder = new StringBuilder();
+ encode(builder, strings);
+ return builder.toString();
+ }
}
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=1621332&r1=1621331&r2=1621332&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 Fri Aug 29 16:00:50 2014
@@ -160,9 +160,10 @@ public class SheetRenderer extends Layou
final UIReload update = (UIReload) facetReload;
writer.writeAttribute(DataAttributes.RELOAD, update.getFrequency());
}
-
- writer.writeAttribute(DataAttributes.PARTIALLY,
- HtmlRendererUtils.getRenderedPartiallyJavascriptArray(facesContext, sheet, sheet), false);
+ final String[] clientIds = ComponentUtils.evaluateClientIds(facesContext, sheet, sheet.getRenderedPartially());
+ if (clientIds.length > 0) {
+ writer.writeAttribute(DataAttributes.PARTIALLY, JsonUtils.encode(clientIds), true);
+ }
writer.writeAttribute(DataAttributes.SELECTION_MODE, sheet.getSelectable(), false);
writer.writeAttribute(DataAttributes.FIRST, Integer.toString(sheet.getFirst()), false);
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=1621332&r1=1621331&r2=1621332&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 Fri Aug 29 16:00:50 2014
@@ -54,13 +54,11 @@ import javax.el.ELContext;
import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
-import javax.faces.component.UINamingContainer;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.model.SelectItem;
import javax.faces.model.SelectItemGroup;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
@@ -440,6 +438,10 @@ public final class HtmlRendererUtils {
}
}
+ /**
+ * @deprecated Since Tobago 2.0.3.
+ */
+ @Deprecated
public static String getComponentIds(
final FacesContext context, final UIComponent component, final String[] componentId) {
final StringBuilder sb = new StringBuilder();
@@ -448,7 +450,7 @@ public final class HtmlRendererUtils {
if (sb.length() > 0) {
sb.append(",");
}
- final String clientId = getComponentId(context, component, id);
+ final String clientId = ComponentUtils.evaluateClientId(context, component, id);
if (clientId != null) {
sb.append(clientId);
}
@@ -457,36 +459,22 @@ public final class HtmlRendererUtils {
return sb.toString();
}
+ /**
+ * @deprecated Since 2.0.3, please use {@link org.apache.myfaces.tobago.util.ComponentUtils#evaluateClientIds(
+ * javax.faces.context.FacesContext, javax.faces.component.UIComponent, String[])}
+ */
public static String[] getComponentIdsAsList(
- final FacesContext context, final UIComponent component, final String[] componentId) {
- final List<String> result = new ArrayList<String>(componentId.length);
- for (final String id : componentId) {
- if (!StringUtils.isBlank(id)) {
- final String clientId = getComponentId(context, component, id);
- if (clientId != null) {
- result.add(clientId);
- }
- }
- }
- return (String[]) result.toArray(new String[result.size()]);
+ final FacesContext context, final UIComponent component, final String[] componentIds) {
+ return ComponentUtils.evaluateClientIds(context, component, componentIds);
}
+ /**
+ * @deprecated Since 2.0.3, please use {@link org.apache.myfaces.tobago.util.ComponentUtils#evaluateClientId(
+ * javax.faces.context.FacesContext, javax.faces.component.UIComponent, String)}
+ */
public static String getComponentId(
final FacesContext context, final UIComponent component, final String componentId) {
- final UIComponent partiallyComponent = ComponentUtils.findComponent(component, componentId);
- if (partiallyComponent != null) {
- final String clientId = partiallyComponent.getClientId(context);
- if (partiallyComponent instanceof UISheet) {
- final int rowIndex = ((UISheet) partiallyComponent).getRowIndex();
- if (rowIndex >= 0 && clientId.endsWith(Integer.toString(rowIndex))) {
- return clientId.substring(0, clientId.lastIndexOf(UINamingContainer.getSeparatorChar(context)));
- }
- }
- return clientId;
- }
- LOG.error("No component found for id='" + componentId + "', "
- + "search base component is '" + component.getClientId(context) + "'");
- return null;
+ return ComponentUtils.evaluateClientId(context, component, componentId);
}
/**
@@ -540,6 +528,10 @@ public final class HtmlRendererUtils {
}
}
+ /**
+ * @deprecated Since Tobago 2.0.3, because of CSP.
+ */
+ @Deprecated
public static String getJavascriptString(final String str) {
if (str != null) {
return "\"" + str + "\"";
@@ -547,6 +539,10 @@ public final class HtmlRendererUtils {
return null;
}
+ /**
+ * @deprecated Since Tobago 2.0.3, because of CSP.
+ */
+ @Deprecated
public static String getRenderedPartiallyJavascriptArray(final FacesContext facesContext, final UICommand command) {
if (command == null) {
return null;
@@ -554,6 +550,10 @@ public final class HtmlRendererUtils {
return getRenderedPartiallyJavascriptArray(facesContext, command, command);
}
+ /**
+ * @deprecated Since Tobago 2.0.3, because of CSP.
+ */
+ @Deprecated
public static String getRenderedPartiallyJavascriptArray(
final FacesContext facesContext, final UIComponent searchBase,
final SupportsRenderedPartially supportsRenderedPartially) {
@@ -568,13 +568,17 @@ public final class HtmlRendererUtils {
strBuilder.append(",");
}
strBuilder.append("\"");
- strBuilder.append(HtmlRendererUtils.getComponentId(facesContext, searchBase, list[i]));
+ strBuilder.append(ComponentUtils.evaluateClientId(facesContext, searchBase, list[i]));
strBuilder.append("\"");
}
strBuilder.append("]");
return strBuilder.toString();
}
+ /**
+ * @deprecated Since Tobago 2.0.3, because of CSP.
+ */
+ @Deprecated
public static String getJavascriptArray(final String[] list) {
final StringBuilder strBuilder = new StringBuilder();
strBuilder.append("[");
@@ -736,13 +740,20 @@ public final class HtmlRendererUtils {
return false;
}
-
+ /**
+ * @deprecated Since Tobago 2.0.0. Because of CSP.
+ */
+ @Deprecated
public static void checkForCommandFacet(
final UIComponent component, final FacesContext facesContext, final TobagoResponseWriter writer)
throws IOException {
checkForCommandFacet(component, Arrays.asList(component.getClientId(facesContext)), facesContext, writer);
}
+ /**
+ * @deprecated Since Tobago 2.0.0. Because of CSP.
+ */
+ @Deprecated
public static void checkForCommandFacet(
final UIComponent component, final List<String> clientIds, final FacesContext facesContext,
final TobagoResponseWriter writer) throws IOException {
@@ -758,6 +769,10 @@ public final class HtmlRendererUtils {
}
}
+ /**
+ * @deprecated Since Tobago 2.0.0. Because of CSP.
+ */
+ @Deprecated
private static void addCommandFacet(
final List<String> clientIds, final Map.Entry<String, UIComponent> facetEntry,
final FacesContext facesContext, final TobagoResponseWriter writer)
@@ -787,7 +802,7 @@ public final class HtmlRendererUtils {
writer.write(HtmlRendererUtils.getComponentIds(facesContext, facetEntry.getValue(),
((UICommand) facetEntry.getValue()).getRenderedPartially()));
writer.write("','");
- writer.write(facetEntry.getValue().getClientId(facesContext));
+ writer.write(facetEntry.getValue().getClientId(facesContext));
writer.write("', {})});\n");
writer.write("};");
writer.endJavascript();
@@ -871,6 +886,10 @@ public final class HtmlRendererUtils {
}
}
+ /**
+ * @deprecated Since Tobago 2.0.3. Because of CSP.
+ */
+ @Deprecated
public static void addAcceleratorKey(
final FacesContext facesContext, final UIComponent component, final Character accessKey) {
final String clientId = component.getClientId(facesContext);
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.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-sheet.js?rev=1621332&r1=1621331&r2=1621332&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js Fri Aug 29 16:00:50 2014
@@ -27,8 +27,9 @@ Tobago.Sheets = {
}
};
-Tobago.Sheet = function(sheetId, unused1, unused2, unused3, unused4,
- clickActionId, clickReloadComponentId, dblClickActionId, dblClickReloadComponentId, renderedPartially) {
+Tobago.Sheet = function(
+ sheetId, unused1, unused2, unused3, unused4,
+ clickActionId, clickReloadComponentId, dblClickActionId, dblClickReloadComponentId, renderedPartially) {
console.debug("New Sheet with id " + sheetId); // @DEV_ONLY
console.time("[tobago-sheet] constructor"); // @DEV_ONLY
this.id = sheetId;
@@ -70,8 +71,7 @@ Tobago.Sheet.init = function(elements) {
click != undefined ? click.partially : undefined,
dblclick != undefined ? dblclick.action : undefined,
dblclick != undefined ? dblclick.partially: undefined,
- // todo: use sheet.data("data-tobago-partially"). What is the type? Array? Test it.
- sheet.attr("data-tobago-partially"));
+ sheet.data("tobago-partially")); // type array
});
Tobago.Sheet.setup2(sheets);