Skip to content

Commit

Permalink
Merge pull request #32302 from mkouba/qute-fix-cdi-ns-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi authored Mar 31, 2023
2 parents c8cacd0 + ed7e3c5 commit 4ba0807
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,8 @@ static Match validateNestedExpressions(QuteConfig config, TemplateAnalysis templ
BeanInfo bean = findBean(expression, index, incorrectExpressions, namedBeans);
if (bean != null) {
rootClazz = bean.getImplClazz();
// Skip the first part - the name of the bean, e.g. for {inject:foo.name} we start validation with "name"
match.setValues(rootClazz, bean.getProviderType());
} else {
// Bean not found
return putResult(match, results, expression);
Expand Down Expand Up @@ -1197,8 +1199,15 @@ static Match validateNestedExpressions(QuteConfig config, TemplateAnalysis templ
}
} else {
if (INJECT_NAMESPACE.equals(namespace) || CDI_NAMESPACE.equals(namespace)) {
// Skip the first part - the name of the bean, e.g. for {inject:foo.name} we start validation with "name"
match.setValues(rootClazz, Type.create(rootClazz.name(), org.jboss.jandex.Type.Kind.CLASS));
if (root.hasHints()) {
// Root is not a type info but a property with hint
// E.g. 'it<loop#123>' and 'STATUS<when#123>'
if (processHints(templateAnalysis, root.asHintInfo().hints, match, index, expression,
generatedIdsToMatches, incorrectExpressions)) {
// In some cases it's necessary to reset the iterator
iterator = parts.iterator();
}
}
} else if (templateData != null) {
// Set the root type and reset the iterator
match.setValues(rootClazz, Type.create(rootClazz.name(), org.jboss.jandex.Type.Kind.CLASS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Inject;
import jakarta.inject.Named;

Expand All @@ -26,6 +27,7 @@ public class NamedBeanIterableReturnTypeTest {
"{@java.lang.String field}"
+ "{#if cdi:validation.hasViolations(field)}"
+ "{#each cdi:validation.getViolations(field)}{it}{/each}"
+ "{#each cdi:violations}:{it.toUpperCase}{/each}"
+ "{/if}"),
"templates/validate.html"));

Expand All @@ -34,7 +36,7 @@ public class NamedBeanIterableReturnTypeTest {

@Test
public void testResult() {
assertEquals("Foo!", validate.data("field", "foo").render());
assertEquals("Foo!:BAR:BAZ", validate.data("field", "foo").render());
}

@ApplicationScoped
Expand All @@ -48,6 +50,12 @@ public boolean hasViolations(String field) {
public List<String> getViolations(String field) {
return List.of("Foo!");
}

@Named("violations")
@Produces
public List<String> getViolations() {
return List.of("bar", "baz");
}
}

}

0 comments on commit 4ba0807

Please sign in to comment.