Skip to content

Commit 23a3c01

Browse files
author
Mario David
committed
fixed ClassCastException that occurs if there is a field injection without being a component
1 parent c0264d8 commit 23a3c01

3 files changed

Lines changed: 34 additions & 26 deletions

File tree

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ apply(plugin: 'cuba')
3434
cuba {
3535
artifact {
3636
group = 'de.balvi.cuba.declarativecontrollers'
37-
version = '0.3'
38-
isSnapshot = false
37+
version = '0.3.1'
38+
isSnapshot = true
3939
}
4040
tomcat {
4141
dir = "$project.rootDir/deploy/tomcat"

modules/web/src/de/balvi/cuba/declarativecontrollers/web/browse/BrowseAnnotationDispatcherBean.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import de.balvi.cuba.declarativecontrollers.web.annotationexecutor.AbstractAnnotationDispatcherBean;
55
import de.balvi.cuba.declarativecontrollers.web.annotationexecutor.browse.BrowseAnnotationExecutor;
66
import de.balvi.cuba.declarativecontrollers.web.annotationexecutor.browse.BrowseFieldAnnotationExecutor;
7-
import groovy.transform.CompileStatic;
87
import org.springframework.stereotype.Component;
98

109
import java.lang.annotation.Annotation;
@@ -26,22 +25,25 @@ private void executeInitForFieldAnnotations(AnnotatableAbstractLookup browse, Ma
2625
Annotation[] fieldAnnotations = field.getAnnotations();
2726

2827
for (Annotation annotation : fieldAnnotations) {
29-
com.haulmont.cuba.gui.components.Component fieldValue = getFieldValue(browse, field);
3028

31-
Collection<BrowseFieldAnnotationExecutor> supportedAnnotations = getSupportedBrowseFieldAnnotationExecutors(annotation);
29+
Collection<BrowseFieldAnnotationExecutor> supportedAnnotationExecutors = getSupportedBrowseFieldAnnotationExecutors(annotation);
3230

33-
for (BrowseFieldAnnotationExecutor annotationExecutor : supportedAnnotations) {
34-
annotationExecutor.init(annotation, browse, fieldValue, params);
31+
if (supportedAnnotationExecutors != null && supportedAnnotationExecutors.size() > 0) {
32+
com.haulmont.cuba.gui.components.Component fieldValue = getFieldValue(browse, field);
33+
for (BrowseFieldAnnotationExecutor annotationExecutor : supportedAnnotationExecutors) {
34+
annotationExecutor.init(annotation, browse, fieldValue, params);
35+
}
3536
}
37+
3638
}
3739
}
3840
}
3941

4042
private void executeInitForClassAnnotations(AnnotatableAbstractLookup browse, Map<String, Object> params) {
4143
for (Annotation annotation : getClassAnnotations(browse)) {
42-
Collection<BrowseAnnotationExecutor> supportedAnnotations = getSupportedBrowseAnnotationExecutors(annotation);
44+
Collection<BrowseAnnotationExecutor> supportedAnnotationExecutors = getSupportedBrowseAnnotationExecutors(annotation);
4345

44-
for (BrowseAnnotationExecutor annotationExecutor : supportedAnnotations) {
46+
for (BrowseAnnotationExecutor annotationExecutor : supportedAnnotationExecutors) {
4547
annotationExecutor.init(annotation, browse, params);
4648
}
4749
}
@@ -60,12 +62,14 @@ private void executeReadyForFieldAnnotations(AnnotatableAbstractLookup browse, M
6062

6163
Annotation[] fieldAnnotations = field.getAnnotations();
6264
for (Annotation annotation : fieldAnnotations) {
63-
com.haulmont.cuba.gui.components.Component fieldValue = getFieldValue(browse, field);
6465

65-
Collection<BrowseFieldAnnotationExecutor> supportedAnnotations = getSupportedBrowseFieldAnnotationExecutors(annotation);
66+
Collection<BrowseFieldAnnotationExecutor> supportedAnnotationExecutors = getSupportedBrowseFieldAnnotationExecutors(annotation);
6667

67-
for (BrowseFieldAnnotationExecutor annotationExecutor : supportedAnnotations) {
68-
annotationExecutor.ready(annotation, browse, fieldValue, params);
68+
if (supportedAnnotationExecutors != null && supportedAnnotationExecutors.size() > 0) {
69+
com.haulmont.cuba.gui.components.Component fieldValue = getFieldValue(browse, field);
70+
for (BrowseFieldAnnotationExecutor annotationExecutor : supportedAnnotationExecutors) {
71+
annotationExecutor.ready(annotation, browse, fieldValue, params);
72+
}
6973
}
7074
}
7175
}

modules/web/src/de/balvi/cuba/declarativecontrollers/web/editor/EditorAnnotationDispatcherBean.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public void executeInit(AnnotatableAbstractEditor editor, Map<String, Object> pa
2525
private void executeInitForClassAnnotations(AnnotatableAbstractEditor editor, Map<String, Object> params) {
2626
for (Annotation annotation : getClassAnnotations(editor)) {
2727

28-
Collection<EditorAnnotationExecutor> supportedAnnotations = getSupportedEditorAnnotationExecutors(annotation);
28+
Collection<EditorAnnotationExecutor> supportedAnnotationExecutors = getSupportedEditorAnnotationExecutors(annotation);
2929

30-
for (EditorAnnotationExecutor annotationExecutor : supportedAnnotations) {
30+
for (EditorAnnotationExecutor annotationExecutor : supportedAnnotationExecutors) {
3131
annotationExecutor.init(annotation, editor, params);
3232
}
3333
}
@@ -37,13 +37,16 @@ private void executeInitForFieldAnnotations(AnnotatableAbstractEditor editor, Ma
3737
for (Field field : getDeclaredFields(editor)) {
3838
Annotation[] fieldAnnotations = field.getAnnotations();
3939
for (Annotation annotation : fieldAnnotations) {
40-
com.haulmont.cuba.gui.components.Component fieldValue = getFieldValue(editor, field);
4140

42-
Collection<EditorFieldAnnotationExecutor> supportedAnnotations = getSupportedEditorFieldAnnotationExecutors(annotation);
41+
Collection<EditorFieldAnnotationExecutor> supportedAnnotationExecutors = getSupportedEditorFieldAnnotationExecutors(annotation);
4342

44-
for (EditorFieldAnnotationExecutor annotationExecutor : supportedAnnotations) {
45-
annotationExecutor.init(annotation, editor, fieldValue, params);
43+
if (supportedAnnotationExecutors != null && supportedAnnotationExecutors.size() > 0) {
44+
com.haulmont.cuba.gui.components.Component fieldValue = getFieldValue(editor, field);
45+
for (EditorFieldAnnotationExecutor annotationExecutor : supportedAnnotationExecutors) {
46+
annotationExecutor.init(annotation, editor, fieldValue, params);
47+
}
4648
}
49+
4750
}
4851
}
4952
}
@@ -59,12 +62,13 @@ private void executeInitForFieldAnnotations(AnnotatableAbstractEditor editor) {
5962
for (Field field : getDeclaredFields(editor)) {
6063
Annotation[] fieldAnnotations = field.getAnnotations();
6164
for (Annotation annotation : fieldAnnotations) {
62-
com.haulmont.cuba.gui.components.Component fieldValue = getFieldValue(editor, field);
63-
64-
Collection<EditorFieldAnnotationExecutor> supportedAnnotations = getSupportedEditorFieldAnnotationExecutors(annotation);
65+
Collection<EditorFieldAnnotationExecutor> supportedAnnotationExecutors = getSupportedEditorFieldAnnotationExecutors(annotation);
6566

66-
for (EditorFieldAnnotationExecutor annotationExecutor : supportedAnnotations) {
67-
annotationExecutor.postInit(annotation, editor, fieldValue);
67+
if (supportedAnnotationExecutors != null && supportedAnnotationExecutors.size() > 0) {
68+
com.haulmont.cuba.gui.components.Component fieldValue = getFieldValue(editor, field);
69+
for (EditorFieldAnnotationExecutor annotationExecutor : supportedAnnotationExecutors) {
70+
annotationExecutor.postInit(annotation, editor, fieldValue);
71+
}
6872
}
6973
}
7074
}
@@ -74,9 +78,9 @@ private void executePostInitForClassAnnotations(AnnotatableAbstractEditor editor
7478

7579
for (Annotation annotation : getClassAnnotations(editor)) {
7680

77-
Collection<EditorAnnotationExecutor> supportedAnnotations = getSupportedEditorAnnotationExecutors(annotation);
81+
Collection<EditorAnnotationExecutor> supportedAnnotationExecutors = getSupportedEditorAnnotationExecutors(annotation);
7882

79-
for (EditorAnnotationExecutor annotationExecutor : supportedAnnotations) {
83+
for (EditorAnnotationExecutor annotationExecutor : supportedAnnotationExecutors) {
8084
annotationExecutor.postInit(annotation, editor);
8185
}
8286
}

0 commit comments

Comments
 (0)