You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by jw...@apache.org on 2008/02/13 19:59:47 UTC
svn commit: r627561 - in /myfaces/trinidad/branches/jwaldman_1.2-issue936:
trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/
trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/
trinidad-examples/trinidad-demo/src/main/java/org/a...
Author: jwaldman
Date: Wed Feb 13 10:59:41 2008
New Revision: 627561
URL: http://svn.apache.org/viewvc?rev=627561&view=rev
Log:
make the findRelativeComponent method do the right thing.
Also make it backward compatible.
Change RequestContextImpl's method to use the new findRelativeComponent
Modified:
myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ComponentUtils.java
myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts
myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TestRelativePartialTriggers.java
myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-examples/trinidad-demo/src/main/webapp/demos/testRelativePartialTriggers.jspx
myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-examples/trinidad-demo/src/main/webapp/demos/testRelativePartialTriggersPrevRelease.jspx
myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java
Modified: myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ComponentUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ComponentUtils.java?rev=627561&r1=627560&r2=627561&view=diff
==============================================================================
--- myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ComponentUtils.java (original)
+++ myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ComponentUtils.java Wed Feb 13 10:59:41 2008
@@ -25,6 +25,8 @@
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+
/**
* Utility functions used by the Apache Trinidad components.
* <p>
@@ -324,9 +326,9 @@
* <p>
* The relative ID must account for NamingContainers. If the component is already inside
* of a naming container, you can use a single colon to start the search from the root,
- * or multiple colons to move up through the NamingContainers - "::" will search from
- * the parent naming container, ":::" will search from the grandparent
- * naming container, etc.
+ * or multiple colons to move up through the NamingContainers - "::" will
+ * pop out of the current naming container, ":::" will[pop out of two
+ * naming containers, etc.
* </p>
*
* @param from the component to search relative to
@@ -337,6 +339,98 @@
UIComponent from,
String relativeId)
{
+ if (from == null)
+ return null;
+ UIComponent originalFrom = from;
+ String originalRelativeId = relativeId;
+
+ int idLength = relativeId.length();
+ // Figure out how many colons
+ int colonCount = 0;
+ while (colonCount < idLength)
+ {
+ if (relativeId.charAt(colonCount) != NamingContainer.SEPARATOR_CHAR)
+ break;
+ colonCount++;
+ }
+
+ // colonCount == 0: fully relative
+ // colonCount == 1: absolute (still normal findComponent syntax)
+ // colonCount > 1: for each extra colon after 1, pop out of
+ // the naming container (to the view root, if naming containers run out)
+ if (colonCount > 1)
+ {
+ relativeId = relativeId.substring(colonCount);
+
+ // if the component is not a NamingContainer, then we need to
+ // get the component's naming container and set this as the 'from'.
+ // this way we'll pop out of the component's
+ // naming container if there is are multiple colons.
+ if (!(from instanceof NamingContainer))
+ {
+ from = _getParentNamingContainer(from);
+ }
+
+ // pop out of the naming containers if there are multiple colons
+ for (int j = 1; j < colonCount; j++)
+ {
+ from = _getParentNamingContainer(from);
+ }
+ }
+
+ UIComponent found = from.findComponent(relativeId);
+ if (found != null)
+ return found;
+ else
+ {
+ // try the old way for backward compatability as far as it differed,
+ // which is only if the 'from' was not a NamingContainer.
+ if (!(originalFrom instanceof NamingContainer))
+ return _findRelativeComponentDeprecated(originalFrom, originalRelativeId);
+ else
+ return null;
+ }
+
+ }
+
+ // given a component, get its naming container. If the component
+ // is a naming container, it will get its naming container.
+ private static UIComponent _getParentNamingContainer (
+ UIComponent from)
+ {
+ while (from.getParent() != null)
+ {
+ from = from.getParent();
+ if (from instanceof NamingContainer)
+ break;
+ }
+ return from;
+ }
+
+ /**
+ * Find a component relative to another.
+ * This method is the same as the 'old' public findRelativeComponentDeprecated.
+ * This method is around so that the
+ * new findRelativeComponent method is backward compatibility.
+ * <p>
+ * The relative ID must account for NamingContainers. If the component is already inside
+ * of a naming container, you can use a single colon to start the search from the root,
+ * or multiple colons to move up through the NamingContainers - "::" will search from
+ * the parent naming container, ":::" will search from the grandparent
+ * naming container, etc.
+ * </p>
+ *
+ * @param from the component to search relative to
+ * @param relativeId the relative path to the component to find
+ * @return the component if found, null otherwise
+ */
+ private static UIComponent _findRelativeComponentDeprecated(
+ UIComponent from,
+ String relativeId)
+ {
+ UIComponent originalFrom = from;
+ String originalRelativeId = relativeId;
+
int idLength = relativeId.length();
// Figure out how many colons
int colonCount = 0;
@@ -365,7 +459,15 @@
}
}
- return from.findComponent(relativeId);
+ UIComponent found = from.findComponent(relativeId);
+ if (found != null)
+ {
+ _LOG.warning("DEPRECATED_TRIGGER_SYNTAX",
+ new Object[] {originalRelativeId, originalFrom});
+ }
+ return found;
}
-
+
+ static private final TrinidadLogger _LOG =
+ TrinidadLogger.createTrinidadLogger(ComponentUtils.class);
}
Modified: myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts?rev=627561&r1=627560&r2=627561&view=diff
==============================================================================
--- myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts (original)
+++ myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts Wed Feb 13 10:59:41 2008
@@ -396,4 +396,7 @@
<!-- RESOURCE_PATH_CONTAINS_DOTS -->
<resource key="RESOURCE_PATH_DOTS">The resource path {0} contains "..". Browsers resolve out the "..", so this is a suspicious path.</resource>
+<!-- DEPRECATED_TRIGGER_SYNTAX -->
+<resource key="DEPRECATED_TRIGGER_SYNTAX">Could not find partial trigger {0} from {1} with the supported partialTriggers syntax. The partial trigger was found with the deprecated syntax. Please use the supported syntax.</resource>
+
</resources>
Modified: myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TestRelativePartialTriggers.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TestRelativePartialTriggers.java?rev=627561&r1=627560&r2=627561&view=diff
==============================================================================
--- myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TestRelativePartialTriggers.java (original)
+++ myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TestRelativePartialTriggers.java Wed Feb 13 10:59:41 2008
@@ -195,6 +195,8 @@
{
if (outputText1x != null)
outputText1x.setInlineStyle("color: aqua");
+ if (commandButton1x != null)
+ commandButton1x.setInlineStyle("color: aqua");
}
Modified: myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-examples/trinidad-demo/src/main/webapp/demos/testRelativePartialTriggers.jspx
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-examples/trinidad-demo/src/main/webapp/demos/testRelativePartialTriggers.jspx?rev=627561&r1=627560&r2=627561&view=diff
==============================================================================
--- myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-examples/trinidad-demo/src/main/webapp/demos/testRelativePartialTriggers.jspx (original)
+++ myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-examples/trinidad-demo/src/main/webapp/demos/testRelativePartialTriggers.jspx Wed Feb 13 10:59:41 2008
@@ -71,7 +71,7 @@
<tr:inputText value="#{row.name}" id="inputText3"
binding="#{testTriggers.inputText3}"
partialTriggers=":::commandButton1 commandButton3"/>
- <tr:commandButton text="Refresh table"
+ <tr:commandButton text="Make table pink"
action="#{testTriggers.commandButton3_action}"
id="commandButton3" partialSubmit="true"/>
</tr:panelGroupLayout>
@@ -82,6 +82,10 @@
id="commandButton4" partialSubmit="true"/>
</f:subview>
<tr:separator/>
+ <tr:panelGroupLayout layout="vertical">
+ <tr:outputText styleClass="AFInstructionText"
+ value="table's partialTrigger is the first command button on the page. Nobody is listening for the inputText's to change."/>
+ </tr:panelGroupLayout>
<f:subview id="nc5">
<tr:panelHeader text="Header">
<tr:table value="#{testTriggers.tableData}" id="table2"
@@ -91,16 +95,23 @@
<tr:inputText value="#{row.name}" id="inputText4" autoSubmit="true"/>
</tr:column>
</tr:table>
- <tr:commandButton text="table peer button" id="commandButton5" partialTriggers="table2"/>
</tr:panelHeader>
</f:subview>
- <!-- type in inputText, outputText should turn red, commandButton's background-color changes -->
+ <!-- type in inputText, outputText should turn red, commandButton's color turns red -->
<!-- click on the button, the outputText should turn pink -->
<!-- select a row in the table, and the outputText should turn aqua -->
+ <tr:panelGroupLayout layout="vertical">
+ <tr:outputText styleClass="AFInstructionText"
+ value="type in inputText, outputText should turn red, commandButton's color turns red"/>
+ <tr:outputText styleClass="AFInstructionText"
+ value="click on the button, the outputText should turn pink"/>
+ <tr:outputText styleClass="AFInstructionText"
+ value="select a row in the table, and the outputText should turn aqua, button color turns aqua"/>
+ </tr:panelGroupLayout>
<tr:commandButton id="commandButton1x" action="#{testTriggers.commandButton1x_action}" text="Make output pink"
binding="#{testTriggers.commandButton1x}"
- partialTriggers="table1x:inputText1x"/>
+ partialTriggers="table1x:inputText1x table1x"/>
<tr:table id="table1x" value="#{testTriggers.tableData}" autoSubmit="true" rowSelection="single" selectionListener="#{testTriggers.tableRowSelected}" >
<tr:column>
<tr:inputText id="inputText1x" autoSubmit="true" valueChangeListener="#{testTriggers.input1xChanged}"/>
@@ -114,6 +125,10 @@
</f:subview>
<!-- a couple of ways you can do the same thing -->
+ <tr:panelGroupLayout layout="vertical">
+ <tr:outputText styleClass="AFInstructionText"
+ value="type in inputText, and see the value in the fields below"/>
+ </tr:panelGroupLayout>
<tr:subform id="autosf">
<tr:inputText autoSubmit="true" id="inputText5" label="inputText"
value="#{testTriggers.inputText5Value}"/>
Modified: myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-examples/trinidad-demo/src/main/webapp/demos/testRelativePartialTriggersPrevRelease.jspx
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-examples/trinidad-demo/src/main/webapp/demos/testRelativePartialTriggersPrevRelease.jspx?rev=627561&r1=627560&r2=627561&view=diff
==============================================================================
--- myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-examples/trinidad-demo/src/main/webapp/demos/testRelativePartialTriggersPrevRelease.jspx (original)
+++ myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-examples/trinidad-demo/src/main/webapp/demos/testRelativePartialTriggersPrevRelease.jspx Wed Feb 13 10:59:41 2008
@@ -94,13 +94,21 @@
</tr:panelHeader>
</f:subview>
-
- <!-- type in inputText, outputText should turn red, commandButton's background-color changes -->
+
+ <!-- type in inputText, outputText should turn red, commandButton's color turns red -->
<!-- click on the button, the outputText should turn pink -->
<!-- select a row in the table, and the outputText should turn aqua -->
+ <tr:panelGroupLayout layout="vertical">
+ <tr:outputText styleClass="AFInstructionText"
+ value="type in inputText, outputText should turn red, commandButton's color turns red"/>
+ <tr:outputText styleClass="AFInstructionText"
+ value="click on the button, the outputText should turn pink"/>
+ <tr:outputText styleClass="AFInstructionText"
+ value="select a row in the table, and the outputText should turn aqua, button color turns aqua"/>
+ </tr:panelGroupLayout>
<tr:commandButton id="commandButton1x" action="#{testTriggers.commandButton1x_action}" text="Make output pink"
binding="#{testTriggers.commandButton1x}"
- partialTriggers="table1x:inputText1x"/>
+ partialTriggers="table1x:inputText1x table1x"/>
<tr:table id="table1x" value="#{testTriggers.tableData}" autoSubmit="true" rowSelection="single" selectionListener="#{testTriggers.tableRowSelected}" >
<tr:column>
<tr:inputText id="inputText1x" autoSubmit="true" valueChangeListener="#{testTriggers.input1xChanged}"/>
@@ -109,7 +117,7 @@
<tr:outputText id="outputText1x" partialTriggers="::inputText1x :::commandButton1x :::table1x" value="hello, outputText"
binding ="#{testTriggers.outputText1x}"/>
</tr:column>
- </tr:table>
+ </tr:table>
</f:subview>
</tr:panelPage>
</tr:form>
Modified: myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java?rev=627561&r1=627560&r2=627561&view=diff
==============================================================================
--- myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java (original)
+++ myfaces/trinidad/branches/jwaldman_1.2-issue936/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java Wed Feb 13 10:59:41 2008
@@ -537,41 +537,24 @@
for (int i = 0; i < triggers.length; i++)
{
String trigger = triggers[i];
+
+
+ UIComponent master = ComponentUtils.findRelativeComponent(listener, trigger);
- // if naming container, then use at naming container to start
- // the findRelativeComponent.
- // if not naming container, find the naming container and start the
- // findRelativeComponent from there.
- // '::' will pop out of the naming container (including itself if
- // the listener is a NamingContainer). Each additional ':' will pop
- // out of the next naming container.
- UIComponent from = listener;
- if (!(listener instanceof NamingContainer))
- {
- // get the component's naming container as the 'from'.
- while (from.getParent() != null)
- {
- from = from.getParent();
- if (from instanceof NamingContainer)
- break;
- }
- }
- UIComponent master = ComponentUtils.findRelativeComponent(from, trigger);
-
boolean deprecatedFind = false;
+
if (master == null)
{
+ UIComponent from = listener;
// backward compatible code
// The old rule is "if the component is a naming container, search relative
// to the parent; otherwise, search relative to the component."
if (listener instanceof NamingContainer)
{
from = listener.getParent();
- }
- else
- from = listener;
- master = ComponentUtils.findRelativeComponent(from, trigger);
- deprecatedFind = true;
+ master = ComponentUtils.findRelativeComponent(from, trigger);
+ deprecatedFind = true;
+ }
}
if (master == null)