This is an automated email from the ASF dual-hosted git repository. ahuber pushed a commit to branch 3407-incubator.thymeleaf in repository https://gitbox.apache.org/repos/asf/causeway.git
commit 49293b9859f113152100ad341f8b6aaf0560d0c0 Author: Andi Huber <[email protected]> AuthorDate: Sat Apr 8 09:52:53 2023 +0200 CAUSEWAY-3407: intermediate experiments with webflux - cannot activate while spring-mvc is present --- examples/demo/domain/pom.xml | 4 - examples/demo/testing/pom.xml | 28 +++-- .../java/demoapp/webapp/vaadin/DemoAppVaadin.java | 5 - examples/demo/web/pom.xml | 71 ++++++++----- .../java/demoapp/web/DemoAppManifestCommon.java | 8 -- .../web/_infra/utils/ThereCanBeOnlyOne.java | 87 ---------------- examples/demo/wicket/common/pom.xml | 4 + .../wicket/common/ui/DemoAppWicketCommon.java | 2 + incubator/viewers/thymeflux/test/pom.xml | 8 ++ .../thymeflux/test/ThymefluxFeaturesApp.java | 4 + .../ThymefluxConfig_customViewResolution.java | 113 +++++++++++++++++++++ .../config/ThymefluxConfig_usingThymeleaf.java | 88 ++++++++++++++++ .../test/features/ThymefluxFeaturesController.java | 5 +- .../src/main/resources/templates/features.html | 104 ++++++++++++++++++- incubator/viewers/thymeflux/viewer/pom.xml | 3 +- viewers/restfulobjects/viewer/pom.xml | 2 +- viewers/wicket/ui/pom.xml | 1 - 17 files changed, 394 insertions(+), 143 deletions(-) diff --git a/examples/demo/domain/pom.xml b/examples/demo/domain/pom.xml index 190d3a1be7..15a984fd92 100644 --- a/examples/demo/domain/pom.xml +++ b/examples/demo/domain/pom.xml @@ -59,10 +59,6 @@ <artifactId>causeway-extensions-pdfjs-applib</artifactId> </dependency> - <dependency> - <groupId>org.apache.causeway.extensions</groupId> - <artifactId>causeway-extensions-exceldownload-wicket-ui</artifactId> - </dependency> <dependency> <groupId>org.apache.causeway.extensions</groupId> <artifactId>causeway-extensions-secman-integration</artifactId> diff --git a/examples/demo/testing/pom.xml b/examples/demo/testing/pom.xml index a96ccaf77d..80a0ebe4f2 100644 --- a/examples/demo/testing/pom.xml +++ b/examples/demo/testing/pom.xml @@ -29,20 +29,34 @@ <dependencies> - <!-- WEB APPLICATION DEPENDENCY BUNDLE --> + <!-- CAUSEWAY API --> + + <dependency> + <groupId>org.apache.causeway.core</groupId> + <artifactId>causeway-applib</artifactId> + </dependency> <dependency> - <groupId>org.apache.causeway.mavendeps</groupId> - <artifactId>causeway-mavendeps-webapp</artifactId> - <type>pom</type> + <groupId>org.apache.causeway.core</groupId> + <artifactId>causeway-schema</artifactId> </dependency> - <!-- DEMO DOMAIN --> + <dependency> + <groupId>org.apache.causeway.core</groupId> + <artifactId>causeway-core-security</artifactId> + </dependency> + <dependency> + <groupId>org.apache.causeway.security</groupId> + <artifactId>causeway-security-bypass</artifactId> + </dependency> <dependency> - <groupId>org.apache.causeway.examples.apps</groupId> - <artifactId>demo-domain</artifactId> + <groupId>org.apache.causeway.core</groupId> + <artifactId>causeway-core-runtimeservices</artifactId> </dependency> + + + <!-- DEMO DOMAIN + WEB --> <dependency> <groupId>org.apache.causeway.examples.apps</groupId> diff --git a/examples/demo/vaadin/src/main/java/demoapp/webapp/vaadin/DemoAppVaadin.java b/examples/demo/vaadin/src/main/java/demoapp/webapp/vaadin/DemoAppVaadin.java index dad306bc56..93661043df 100644 --- a/examples/demo/vaadin/src/main/java/demoapp/webapp/vaadin/DemoAppVaadin.java +++ b/examples/demo/vaadin/src/main/java/demoapp/webapp/vaadin/DemoAppVaadin.java @@ -37,7 +37,6 @@ import org.apache.causeway.valuetypes.markdown.metamodel.CausewayModuleValMarkdo import org.apache.causeway.valuetypes.markdown.persistence.jdo.dn.CausewayModuleValMarkdownPersistenceJdoDn; import org.apache.causeway.valuetypes.vega.metamodel.CausewayModuleValVegaMetaModel; import org.apache.causeway.valuetypes.vega.persistence.jdo.dn.CausewayModuleValVegaPersistenceJdoDn; -import org.apache.causeway.viewer.wicket.viewer.CausewayModuleViewerWicketViewer; import demoapp.dom.DemoModuleCommon; import demoapp.web.DemoAppManifestJdo; @@ -65,12 +64,8 @@ import demoapp.web.DemoAppManifestJdo; CausewayModuleValMarkdownPersistenceJdoDn.class, CausewayModuleValVegaPersistenceJdoDn.class, - - // WICKET INTEGRATION ... to allow side by side comparison - CausewayModuleViewerWicketViewer.class, // wicket viewer CausewayModuleExtSseWicket.class, // server sent events CausewayModuleValAsciidocUiWkt.class, // ascii-doc rendering support (for Wicket) - }) public class DemoAppVaadin extends SpringBootServletInitializer { diff --git a/examples/demo/web/pom.xml b/examples/demo/web/pom.xml index d69b111e34..cdc5680a01 100644 --- a/examples/demo/web/pom.xml +++ b/examples/demo/web/pom.xml @@ -33,12 +33,52 @@ <dependencies> - <!-- WEB APPLICATION DEPENDENCY BUNDLE --> + <!-- SPRING --> <dependency> - <groupId>org.apache.causeway.mavendeps</groupId> - <artifactId>causeway-mavendeps-webapp</artifactId> - <type>pom</type> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <exclusions> + <exclusion> + <!-- there is also webflux, that we could want to use instead--> + <groupId>org.springframework</groupId> + <artifactId>spring-webmvc</artifactId> + </exclusion> + <exclusion> + <!-- not needed if wicket or resteasy are used--> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-thymeleaf</artifactId> + </exclusion> + <exclusion> + <groupId>javax.validation</groupId> + <artifactId>validation-api</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-jcl</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + <scope>provided</scope> + </dependency> + + <!-- CAUSEWAY --> + + <dependency> + <groupId>org.apache.causeway.core</groupId> + <artifactId>causeway-core-security</artifactId> + </dependency> + <dependency> + <groupId>org.apache.causeway.security</groupId> + <artifactId>causeway-security-bypass</artifactId> </dependency> <!-- DEMO DOMAIN --> @@ -48,8 +88,6 @@ <artifactId>demo-domain</artifactId> </dependency> - - <!-- CORS --> <dependency> @@ -57,29 +95,14 @@ <artifactId>causeway-extensions-cors-impl</artifactId> </dependency> - <!-- Extensions --> + <!-- EXTENSIONS --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> - - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter</artifactId> - <exclusions> - <exclusion> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-log4j2</artifactId> - </dependency> - - + + </dependencies> </project> diff --git a/examples/demo/web/src/main/java/demoapp/web/DemoAppManifestCommon.java b/examples/demo/web/src/main/java/demoapp/web/DemoAppManifestCommon.java index 0b01de431d..c648647c3c 100644 --- a/examples/demo/web/src/main/java/demoapp/web/DemoAppManifestCommon.java +++ b/examples/demo/web/src/main/java/demoapp/web/DemoAppManifestCommon.java @@ -30,10 +30,7 @@ import org.apache.causeway.extensions.cors.impl.CausewayModuleExtCors; import org.apache.causeway.extensions.secman.encryption.spring.CausewayModuleExtSecmanEncryptionSpring; import org.apache.causeway.extensions.secman.integration.CausewayModuleExtSecmanIntegration; import org.apache.causeway.extensions.secman.integration.authenticator.AuthenticatorSecmanAutoConfiguration; -import org.apache.causeway.extensions.viewer.wicket.exceldownload.ui.CausewayModuleExtExcelDownloadWicketUi; import org.apache.causeway.testing.h2console.ui.CausewayModuleTestingH2ConsoleUi; -import org.apache.causeway.viewer.restfulobjects.jaxrsresteasy.CausewayModuleViewerRestfulObjectsJaxrsResteasy; -import org.apache.causeway.viewer.restfulobjects.viewer.CausewayModuleViewerRestfulObjectsViewer; import demoapp.dom._infra.fixtures.DemoFixtureScript; import demoapp.web.security.PrototypeActionsVisibilityAdvisor; @@ -51,15 +48,10 @@ import lombok.extern.log4j.Log4j2; // autoconfig AuthenticatorSecmanAutoConfiguration.class, - // REST - CausewayModuleViewerRestfulObjectsViewer.class, - CausewayModuleViewerRestfulObjectsJaxrsResteasy.class, - // CORS CausewayModuleExtCors.class, CausewayModuleTestingH2ConsoleUi.class, // enables the H2 console menu item - CausewayModuleExtExcelDownloadWicketUi.class, // allows for collection download as excel // services PrototypeActionsVisibilityAdvisor.class, diff --git a/examples/demo/web/src/main/java/demoapp/web/_infra/utils/ThereCanBeOnlyOne.java b/examples/demo/web/src/main/java/demoapp/web/_infra/utils/ThereCanBeOnlyOne.java deleted file mode 100644 index 6b480e6642..0000000000 --- a/examples/demo/web/src/main/java/demoapp/web/_infra/utils/ThereCanBeOnlyOne.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package demoapp.web._infra.utils; - -import java.io.IOException; - -import org.apache.http.HttpHost; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.AuthCache; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.protocol.HttpClientContext; -import org.apache.http.impl.auth.BasicScheme; -import org.apache.http.impl.client.BasicAuthCache; -import org.apache.http.impl.client.BasicCredentialsProvider; -import org.apache.http.impl.client.HttpClientBuilder; -import org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent; -import org.springframework.context.ApplicationListener; -import org.springframework.stereotype.Component; - -import lombok.val; - -@Component -public class ThereCanBeOnlyOne implements ApplicationListener<ServletWebServerInitializedEvent > { - - @Override - public void onApplicationEvent(final ServletWebServerInitializedEvent event) { - final int port = event.getWebServer().getPort(); - - try { - invokeRemoteShutdown(port); - } catch (Exception e) { - // ignore them all - } - - } - - // -- HELPER - - private static void invokeRemoteShutdown(int port) throws IOException { - - val targetHost = new HttpHost("localhost", port, "http"); - val credsProvider = new BasicCredentialsProvider(); - credsProvider.setCredentials( - new AuthScope(targetHost.getHostName(), targetHost.getPort()), - new UsernamePasswordCredentials("sven", "pass")); - - // Create AuthCache instance - AuthCache authCache = new BasicAuthCache(); - // Generate BASIC scheme object and add it to the local auth cache - BasicScheme basicAuth = new BasicScheme(); - authCache.put(targetHost, basicAuth); - - // Add AuthCache to the execution context - HttpClientContext context = HttpClientContext.create(); - context.setCredentialsProvider(credsProvider); - context.setAuthCache(authCache); - - val httpget = new HttpGet("/restful/services/demo.LineBreaker/actions/shutdown/invoke"); - - try(val httpClient = HttpClientBuilder.create().build()){ - try(val response = httpClient.execute(targetHost, httpget, context)) { - response.getEntity(); - } - } - - } - -} - - diff --git a/examples/demo/wicket/common/pom.xml b/examples/demo/wicket/common/pom.xml index 1dbae16c6b..46a540cb69 100644 --- a/examples/demo/wicket/common/pom.xml +++ b/examples/demo/wicket/common/pom.xml @@ -112,6 +112,10 @@ <artifactId>causeway-extensions-fullcalendar-wicket-ui</artifactId> </dependency> + <dependency> + <groupId>org.apache.causeway.extensions</groupId> + <artifactId>causeway-extensions-exceldownload-wicket-ui</artifactId> + </dependency> </dependencies> </project> diff --git a/examples/demo/wicket/common/src/main/java/demoapp/webapp/wicket/common/ui/DemoAppWicketCommon.java b/examples/demo/wicket/common/src/main/java/demoapp/webapp/wicket/common/ui/DemoAppWicketCommon.java index 7b4a68d87b..ec1eddf7c1 100644 --- a/examples/demo/wicket/common/src/main/java/demoapp/webapp/wicket/common/ui/DemoAppWicketCommon.java +++ b/examples/demo/wicket/common/src/main/java/demoapp/webapp/wicket/common/ui/DemoAppWicketCommon.java @@ -22,6 +22,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.apache.causeway.extensions.fullcalendar.wkt.ui.viewer.CausewayModuleExtFullCalendarWicketUi; +import org.apache.causeway.extensions.viewer.wicket.exceldownload.ui.CausewayModuleExtExcelDownloadWicketUi; import demoapp.webapp.wicket.common.ui.custom.WhereInTheWorldPanelFactory; @@ -32,6 +33,7 @@ import demoapp.webapp.wicket.common.ui.custom.WhereInTheWorldPanelFactory; @Import({ WhereInTheWorldPanelFactory.class, CausewayModuleExtFullCalendarWicketUi.class, + CausewayModuleExtExcelDownloadWicketUi.class, // allows for collection download as excel }) public class DemoAppWicketCommon { diff --git a/incubator/viewers/thymeflux/test/pom.xml b/incubator/viewers/thymeflux/test/pom.xml index d6dd1f51e8..1756e7af6e 100644 --- a/incubator/viewers/thymeflux/test/pom.xml +++ b/incubator/viewers/thymeflux/test/pom.xml @@ -43,6 +43,14 @@ <groupId>org.apache.causeway.examples.apps</groupId> <artifactId>demo-testing-jpa</artifactId> <version>${project.version}</version> + <exclusions> + <exclusion> + <groupId>org.apache.causeway.extensions</groupId> + <artifactId> + causeway-extensions-exceldownload-wicket-ui + </artifactId> + </exclusion> + </exclusions> </dependency> <dependency> diff --git a/incubator/viewers/thymeflux/test/src/main/java/org/apache/causeway/viewer/thymeflux/test/ThymefluxFeaturesApp.java b/incubator/viewers/thymeflux/test/src/main/java/org/apache/causeway/viewer/thymeflux/test/ThymefluxFeaturesApp.java index 07ccbc9fe1..f7156a883f 100644 --- a/incubator/viewers/thymeflux/test/src/main/java/org/apache/causeway/viewer/thymeflux/test/ThymefluxFeaturesApp.java +++ b/incubator/viewers/thymeflux/test/src/main/java/org/apache/causeway/viewer/thymeflux/test/ThymefluxFeaturesApp.java @@ -27,6 +27,7 @@ import org.apache.causeway.commons.internal.os._OsUtil; import org.apache.causeway.core.config.presets.CausewayPresets; import org.apache.causeway.security.bypass.CausewayModuleSecurityBypass; import org.apache.causeway.viewer.thymeflux.test.config.ThymefluxConfig_headlessPersistence; +import org.apache.causeway.viewer.thymeflux.test.config.ThymefluxConfig_usingThymeleaf; import org.apache.causeway.viewer.thymeflux.test.features.ThymefluxFeaturesController; import org.apache.causeway.viewer.thymeflux.viewer.CausewayModuleIncViewerThymefluxViewer; @@ -37,12 +38,15 @@ import org.apache.causeway.viewer.thymeflux.viewer.CausewayModuleIncViewerThymef @Import({ CausewayModuleSecurityBypass.class, ThymefluxConfig_headlessPersistence.class, + //ThymefluxConfig_customViewResolution.class, + ThymefluxConfig_usingThymeleaf.class, // THYMEFLUX INTEGRATION CausewayModuleIncViewerThymefluxViewer.class, // FEATURES ThymefluxFeaturesController.class }) +//@EnableAutoConfiguration(exclude = WebMvcAutoConfiguration.class) public class ThymefluxFeaturesApp extends SpringBootServletInitializer { /** diff --git a/incubator/viewers/thymeflux/test/src/main/java/org/apache/causeway/viewer/thymeflux/test/config/ThymefluxConfig_customViewResolution.java b/incubator/viewers/thymeflux/test/src/main/java/org/apache/causeway/viewer/thymeflux/test/config/ThymefluxConfig_customViewResolution.java new file mode 100644 index 0000000000..70a72e68b6 --- /dev/null +++ b/incubator/viewers/thymeflux/test/src/main/java/org/apache/causeway/viewer/thymeflux/test/config/ThymefluxConfig_customViewResolution.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.causeway.viewer.thymeflux.test.config; + +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.time.LocalTime; +import java.util.Locale; +import java.util.Map; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.core.io.buffer.DataBufferUtils; +import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; +import org.springframework.util.FastByteArrayOutputStream; +import org.springframework.web.reactive.config.ViewResolverRegistry; +import org.springframework.web.reactive.config.WebFluxConfigurer; +import org.springframework.web.reactive.result.view.AbstractView; +import org.springframework.web.reactive.result.view.ViewResolver; +import org.springframework.web.server.ServerWebExchange; + +import lombok.extern.log4j.Log4j2; +import reactor.core.publisher.Mono; + +@Configuration +@Log4j2 +public class ThymefluxConfig_customViewResolution implements WebFluxConfigurer { + + @Override + public void configureViewResolvers(final ViewResolverRegistry registry) { + ViewResolver resolver = (viewName, locale) -> Mono.just(new HelloView()); + //registry.viewResolver(resolver); + //registry. + } + + static class HelloView extends AbstractView { + + @Override + public Mono<Void> render(final Map<String, ?> model, final MediaType contentType, final ServerWebExchange exchange) { + log.info("hello render request"); + return super.render(model, contentType, exchange); + } + + @Override + protected Mono<Void> renderInternal(final Map<String, Object> renderAttributes, + @Nullable final MediaType contentType, final ServerWebExchange exchange) { + + return exchange.getResponse().writeWith(Mono + .fromCallable(() -> { + // Expose all standard FreeMarker hash models. + //SimpleHash freeMarkerModel = getTemplateModel(renderAttributes, exchange); + + + log.info(exchange.getLogPrefix() + "Rendering [" + getUrl() + "]"); + + + Locale locale = LocaleContextHolder.getLocale(exchange.getLocaleContext()); + FastByteArrayOutputStream bos = new FastByteArrayOutputStream(); + try { + Charset charset = getCharset(contentType); + Writer writer = new OutputStreamWriter(bos, charset); + //getTemplate(locale).process(freeMarkerModel, writer); + process(renderAttributes, exchange, writer); + + byte[] bytes = bos.toByteArrayUnsafe(); + return exchange.getResponse().bufferFactory().wrap(bytes); + } + catch (IOException ex) { + String message = "Could not load FreeMarker template for URL [" + getUrl() + "]"; + throw new IllegalStateException(message, ex); + } + }) + .doOnDiscard(DataBuffer.class, DataBufferUtils::release)); + } + + private void process(final Map<String, Object> renderAttributes, final ServerWebExchange exchange, final Writer writer) + throws IOException{ + // TODO Auto-generated method stub + writer.append("Hello World! " + LocalTime.now()); + } + + private Charset getCharset(final MediaType contentType) { + return StandardCharsets.UTF_8; + } + + private String getUrl() { + return "dummy"; + } + + } + +} diff --git a/incubator/viewers/thymeflux/test/src/main/java/org/apache/causeway/viewer/thymeflux/test/config/ThymefluxConfig_usingThymeleaf.java b/incubator/viewers/thymeflux/test/src/main/java/org/apache/causeway/viewer/thymeflux/test/config/ThymefluxConfig_usingThymeleaf.java new file mode 100644 index 0000000000..b45eef3382 --- /dev/null +++ b/incubator/viewers/thymeflux/test/src/main/java/org/apache/causeway/viewer/thymeflux/test/config/ThymefluxConfig_usingThymeleaf.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.causeway.viewer.thymeflux.test.config; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.reactive.config.EnableWebFlux; +import org.springframework.web.reactive.config.ViewResolverRegistry; +import org.springframework.web.reactive.config.WebFluxConfigurer; +import org.thymeleaf.spring6.ISpringWebFluxTemplateEngine; +import org.thymeleaf.spring6.SpringWebFluxTemplateEngine; +import org.thymeleaf.spring6.templateresolver.SpringResourceTemplateResolver; +import org.thymeleaf.spring6.view.reactive.ThymeleafReactiveViewResolver; +import org.thymeleaf.templatemode.TemplateMode; + +import lombok.extern.log4j.Log4j2; + +@Configuration +@EnableWebFlux +@Log4j2 +public class ThymefluxConfig_usingThymeleaf implements ApplicationContextAware, WebFluxConfigurer { + + private ApplicationContext ctx; + + @Override + public void setApplicationContext(final ApplicationContext context) { + this.ctx = context; + } + + @Bean + public SpringResourceTemplateResolver thymeleafTemplateResolver() { + + final SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); + resolver.setApplicationContext(this.ctx); + resolver.setPrefix("classpath:/templates/"); + resolver.setSuffix(".html"); + resolver.setTemplateMode(TemplateMode.HTML); + resolver.setCacheable(false); + resolver.setCheckExistence(false); + return resolver; + + } + + @Bean + public ISpringWebFluxTemplateEngine thymeleafTemplateEngine() { + // We override here the SpringTemplateEngine instance that would otherwise be + // instantiated by + // Spring Boot because we want to apply the SpringWebFlux-specific context + // factory, link builder... + final SpringWebFluxTemplateEngine templateEngine = new SpringWebFluxTemplateEngine(); + templateEngine.setTemplateResolver(thymeleafTemplateResolver()); + return templateEngine; + } + + @Bean + public ThymeleafReactiveViewResolver thymeleafChunkedAndDataDrivenViewResolver() { + final ThymeleafReactiveViewResolver viewResolver = new ThymeleafReactiveViewResolver(); + viewResolver.setTemplateEngine(thymeleafTemplateEngine()); +// viewResolver.setOrder(1); +// viewResolver.setViewNames(new String[]{"home"}); + viewResolver.setResponseMaxChunkSizeBytes(8192); // OUTPUT BUFFER size limit + return viewResolver; + } + + @Override + public void configureViewResolvers(final ViewResolverRegistry registry) { + registry.viewResolver(thymeleafChunkedAndDataDrivenViewResolver()); + } + +} diff --git a/incubator/viewers/thymeflux/test/src/main/java/org/apache/causeway/viewer/thymeflux/test/features/ThymefluxFeaturesController.java b/incubator/viewers/thymeflux/test/src/main/java/org/apache/causeway/viewer/thymeflux/test/features/ThymefluxFeaturesController.java index 6707fd327a..67aad4c587 100644 --- a/incubator/viewers/thymeflux/test/src/main/java/org/apache/causeway/viewer/thymeflux/test/features/ThymefluxFeaturesController.java +++ b/incubator/viewers/thymeflux/test/src/main/java/org/apache/causeway/viewer/thymeflux/test/features/ThymefluxFeaturesController.java @@ -21,15 +21,16 @@ package org.apache.causeway.viewer.thymeflux.test.features; import java.time.LocalTime; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; import lombok.RequiredArgsConstructor; -@Controller +//@Controller +@RestController @RequiredArgsConstructor(onConstructor_ = {@Autowired}) public class ThymefluxFeaturesController { diff --git a/incubator/viewers/thymeflux/test/src/main/resources/templates/features.html b/incubator/viewers/thymeflux/test/src/main/resources/templates/features.html index 9978cacd63..15f59ffe1e 100644 --- a/incubator/viewers/thymeflux/test/src/main/resources/templates/features.html +++ b/incubator/viewers/thymeflux/test/src/main/resources/templates/features.html @@ -1,5 +1,5 @@ <!DOCTYPE html> -<!-- Licensed to the Apache Software Foundation (ASF) under one +<!--/* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file @@ -14,21 +14,32 @@ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - under the License. --> + under the License. */--> <html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:hx="http://www.w3.org/1999/xhtml"> + <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + + <!--/* PROTOTYPING --> + <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous"/> + <link href="../static/css/causeway-thymeflux.css" rel="stylesheet" /> + <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3" crossorigin="anonymous" defer></script> + <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-cuYeSxntonz0PPNlHhBs68uyIAVpIIOZZ5JqeqvYYIcEL727kskC66kF92t6Xl2V" crossorigin="anonymous" defer></script> + <!--*/--> + + <!--/*/ <link rel="icon" type="image/x-icon" href="/images/favicon.ico"> <link th:rel="stylesheet" th:href="@{/webjars/bootstrap/5.2.3/css/bootstrap.min.css}" /> <link th:rel="stylesheet" th:href="@{/css/causeway-thymeflux.css}"> - <!-- <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3" crossorigin="anonymous"></script> --> <script th:src="@{/webjars/popper.js/2.9.3/umd/popper.min.js}" defer></script> <script th:src="@{/webjars/bootstrap/5.2.3/js/bootstrap.bundle.min.js}" defer></script> <script th:src="@{/webjars/htmx.org/1.8.6/dist/htmx.min.js}" defer></script> + /*/--> + </head> <body> @@ -118,6 +129,93 @@ </th:block> </p> + + <h2>Dropdown with Form</h3> + <p> + <div class="container"> + <div class="dropdown"> + <button type="button" + class="btn btn-lg btn-success + dropdown-toggle" + data-bs-toggle="dropdown"> + Feedback and Queries + <span class="caret"></span> + </button> + <div class="dropdown-menu col-md-6"> + <form> + <div class="form-group m-1"> + <label for="fm1" class="form-label"> + Email Address + </label> + <input type="email" + class="form-control" + id="fm1" + placeholder="Enter you email address" + required> + </div> + <div class="form-group m-1"> + <label for="fm2" class="form-label"> + Contact Number + </label> + <input type="number" class="form-control" + id="fm2" + placeholder="Your contact number"> + </div> + <div class="form-group m-1"> + <label for="fm3" + class="form-check-label">Gender</label><br> + Male<input type="radio" + class="form-check-input m-1" + name="gen" id="fm3" + value="Male"> + Female<input type="radio" + class="form-check-input m-1" + name="gen" id="fm3" + value="Female"> + </div> + <div class="form-group m-1"> + <label for="fm4" + class="form-check--label"> + Enrolled course + </label> + <br> + <input type="checkbox" + class="form-check-input m-1" + name="enr" id="fm4" value="C"> + C<br> + <input type="checkbox" + class="form-check-input m-1" + name="enr" id="fm4" value="C++"> + C++<br> + <input type="checkbox" + class="form-check-input m-1" + name="enr" id="fm4" value="Python"> + Python<br> + <input type="checkbox" + class="form-check-input m-1" + name="enr" id="fm4" value="C"> + Java + </div> + <div class="form-group m-1"> + <label for="fm3" class="form-label"> + Drop your feedback/Query + </label> + <input type="text" + class="form-control" id="fm3" + required> + </div> + <div class="form-group p-1"> + <button type="submit" + class="btn btn-primary"> + Submit + </button> + </div> + </form> + </div> + </div> + </div> + </p> + </div> diff --git a/incubator/viewers/thymeflux/viewer/pom.xml b/incubator/viewers/thymeflux/viewer/pom.xml index f2af9336fa..026c3f7d82 100644 --- a/incubator/viewers/thymeflux/viewer/pom.xml +++ b/incubator/viewers/thymeflux/viewer/pom.xml @@ -72,7 +72,7 @@ - <!-- TODO remove if already provided by 'model'' artifact--> + <!-- TODO remove if already provided by 'model'' artifact <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactId> @@ -83,6 +83,7 @@ </exclusion> </exclusions> </dependency> + --> </dependencies> diff --git a/viewers/restfulobjects/viewer/pom.xml b/viewers/restfulobjects/viewer/pom.xml index 49c211c00f..963240d3ef 100644 --- a/viewers/restfulobjects/viewer/pom.xml +++ b/viewers/restfulobjects/viewer/pom.xml @@ -56,7 +56,7 @@ <groupId>com.fasterxml.jackson.module</groupId> <artifactId>jackson-module-jakarta-xmlbind-annotations</artifactId> </dependency> - + <!-- TESTING --> <dependency> diff --git a/viewers/wicket/ui/pom.xml b/viewers/wicket/ui/pom.xml index 227f4db264..fbbb3ee699 100644 --- a/viewers/wicket/ui/pom.xml +++ b/viewers/wicket/ui/pom.xml @@ -283,7 +283,6 @@ <dependency> <groupId>org.apache.causeway.valuetypes</groupId> <artifactId>causeway-valuetypes-jodatime-integration</artifactId> - <version>${project.version}</version> <scope>provided</scope> </dependency>
