You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2010/05/01 01:25:05 UTC
svn commit: r939873 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry5/corelib/components/Any.java
test/java/org/apache/tapestry5/corelib/components/AnyTest.java
Author: hlship
Date: Fri Apr 30 23:25:05 2010
New Revision: 939873
URL: http://svn.apache.org/viewvc?rev=939873&view=rev
Log:
TAP5-1031: NPE from Any component when invoking getClientId() before the component renders
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Any.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/AnyTest.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Any.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Any.java?rev=939873&r1=939872&r2=939873&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Any.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Any.java Fri Apr 30 23:25:05 2010
@@ -1,10 +1,10 @@
-// Copyright 2008 The Apache Software Foundation
+// Copyright 2008, 2010 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -19,6 +19,7 @@ import org.apache.tapestry5.annotations.
import org.apache.tapestry5.annotations.SupportsInformalParameters;
import org.apache.tapestry5.dom.Element;
import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.services.javascript.JavascriptSupport;
/**
* Renders an arbitrary element including informal parameters.
@@ -43,7 +44,7 @@ public class Any implements ClientElemen
private ComponentResources resources;
@Inject
- private RenderSupport renderSupport;
+ private JavascriptSupport javascriptSupport;
String defaultElement()
{
@@ -60,18 +61,23 @@ public class Any implements ClientElemen
}
/**
- * Returns the client id. This has side effects: this first time this is called (after the Any component renders
+ * Returns the client id. This has side effects: this first time this is called (after the Any component renders
* its start tag), a unique id is allocated (based on, and typically the same as, the clientId parameter, which
* defaults to the component's id). The rendered element is updated, with its id attribute set to the unique client
* id, which is then returned.
- *
+ *
* @return unique client id for this component
*/
public String getClientId()
{
+ if (anyElement == null)
+ throw new IllegalStateException(String.format(
+ "Unable to provide client id for component %s as it has not yet rendered.", resources
+ .getCompleteId()));
+
if (uniqueId == null)
{
- uniqueId = renderSupport.allocateClientId(clientId);
+ uniqueId = javascriptSupport.allocateClientId(clientId);
anyElement.forceAttributes("id", uniqueId);
}
@@ -83,9 +89,9 @@ public class Any implements ClientElemen
writer.end(); // the element
}
- void inject(RenderSupport support, ComponentResources resources, String element, String clientId)
+ void inject(JavascriptSupport javascriptSupport, ComponentResources resources, String element, String clientId)
{
- this.renderSupport = support;
+ this.javascriptSupport = javascriptSupport;
this.resources = resources;
this.element = element;
this.clientId = clientId;
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/AnyTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/AnyTest.java?rev=939873&r1=939872&r2=939873&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/AnyTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/AnyTest.java Fri Apr 30 23:25:05 2010
@@ -1,10 +1,10 @@
-// Copyright 2008 The Apache Software Foundation
+// Copyright 2008, 2010 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,9 +16,9 @@ package org.apache.tapestry5.corelib.com
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.MarkupWriter;
-import org.apache.tapestry5.RenderSupport;
import org.apache.tapestry5.dom.DefaultMarkupModel;
import org.apache.tapestry5.internal.services.MarkupWriterImpl;
+import org.apache.tapestry5.services.javascript.JavascriptSupport;
import org.apache.tapestry5.test.TapestryTestCase;
import org.testng.annotations.Test;
@@ -28,7 +28,7 @@ public class AnyTest extends TapestryTes
public void render_simple()
{
ComponentResources resources = mockComponentResources();
- RenderSupport support = mockRenderSupport();
+ JavascriptSupport support = mockJavascriptSupport();
MarkupWriter writer = new MarkupWriterImpl(new DefaultMarkupModel());
@@ -52,7 +52,7 @@ public class AnyTest extends TapestryTes
public void render_with_id()
{
ComponentResources resources = mockComponentResources();
- RenderSupport support = mockRenderSupport();
+ JavascriptSupport support = mockJavascriptSupport();
MarkupWriter writer = new MarkupWriterImpl(new DefaultMarkupModel());
@@ -81,6 +81,34 @@ public class AnyTest extends TapestryTes
assertEquals(component.getClientId(), uniqueId);
verify();
+ }
+
+ @Test
+ public void attempt_to_get_client_id_before_render()
+ {
+ ComponentResources resources = mockComponentResources();
+ JavascriptSupport support = mockJavascriptSupport();
+
+ train_getCompleteId(resources, "Foo/bar.baz");
+
+ replay();
+
+ Any component = new Any();
+
+ component.inject(support, resources, "div", null);
+
+ try
+ {
+ component.getClientId();
+ unreachable();
+ }
+ catch (IllegalStateException ex)
+ {
+ assertEquals(ex.getMessage(),
+ "Unable to provide client id for component Foo/bar.baz as it has not yet rendered.");
+ }
+
+ verify();
}
}