Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #476 from nykolaslima/generic-controller-linkTo

Fixing linkTo for GenericController with args. Fixes #464
  • Loading branch information...
commit cba5a003e75df876d29422710deb74a2775a0c54 2 parents b5ad875 + ecd55f5
@lucascs lucascs authored
View
2  vraptor-core/src/main/java/br/com/caelum/vraptor/view/LinkToHandler.java
@@ -80,7 +80,7 @@ public Linker get(Object key) {
}
private Method findMethodWithName(Class<?> type, String name) {
for (Method method : type.getDeclaredMethods()) {
- if (method.getName().equals(name)) {
+ if (!method.isBridge() && method.getName().equals(name)) {
return method;
}
}
View
12 vraptor-core/src/test/java/br/com/caelum/vraptor/view/GenericController.java
@@ -0,0 +1,12 @@
+package br.com.caelum.vraptor.view;
+
+/**
+ * Controller used to test Generic Controllers on LinkToHandler
+ * @author Nykolas Lima
+ *
+ */
+public class GenericController<T> {
+ public void method(T entity) {
+ System.out.println("Do Something");
+ }
+}
View
9 vraptor-core/src/test/java/br/com/caelum/vraptor/view/LinkToHandlerTest.java
@@ -54,6 +54,15 @@ public void shouldReturnWantedUrlWithParamArgs() {
String uri = handler.get(TestController.class).get("method").get(a).get(b).toString();
assertThat(uri, is("/path/expectedURL"));
}
+
+ @Test
+ public void shouldReturnWantedUrlForOverrideMethodWithParamArgs() throws NoSuchMethodException, SecurityException {
+ String a = "test";
+ when(router.urlFor(SubGenericController.class, SubGenericController.class.getDeclaredMethod("method", new Class[]{String.class}), new Object[]{a})).thenReturn("/expectedURL");
+ //${linkTo[TestSubGenericController].method['test']}]
+ String uri = handler.get(SubGenericController.class).get("method").get(a).toString();
+ assertThat(uri, is("/path/expectedURL"));
+ }
static class TestController {
void method(String a, int b) {
View
16 vraptor-core/src/test/java/br/com/caelum/vraptor/view/SubGenericController.java
@@ -0,0 +1,16 @@
+package br.com.caelum.vraptor.view;
+
+/**
+ * Controller used to test Generic Controllers on LinkToHandler
+ * @author Nykolas Lima
+ *
+ */
+public class SubGenericController extends GenericController<String> {
+ public void method(String string) {
+ System.out.println("Do another thing by Sub Generic Controller");
+ }
+
+ public void okMethod(String string) {
+ System.out.println("OKOK");
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.