joinfaces / joinfaces-gradle-jar-example

JoinFaces Gradle Jar Example
5 stars 4 forks source link

Please add "welcome-file" configuration example #101

Open kartu opened 1 month ago

kartu commented 1 month ago

This sample project returns 404 error when opening localhost:8080.

Most users face the "how do I redirect to welcome page" issue, it would be very useful to have it in this example.

larsgrefer commented 2 weeks ago

This is not that easy to do without using additional dependencies.

Do you have an idea how to do it the "best" way?

kartu commented 1 week ago

Sorry for the delayed answer.

I've tried 3 approaches:

1) Simply index.html with redirect meta to index.xhtml <= works 2) Controller redirect <= works, ended up keeping this (implements WebMvcConfigurer)

    // poor man's welcome page configuration
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // Forward requests from "/" to "/index.xhtml"
        registry.addViewController("/")
            .setViewName("forward:/index.xhtml");
    }

NOTE: when I've switched to myfaces to mojarra using joinfaces guide, tomcat initialization params were ignored until I included spring web starter. I didn't check if this approach worked without spring web-starter.

3) Tried the WelcomePageHandlerMappingFactory of Spring. It didn't quite work. While I could "convince" spring that "/index" exists, there is nothing to serve that call. This way, however, feels like the best as it should be able to work or not work depending on the presence of index.xhtml file. Adding a TemplateAvailabilityProvider for xhtml files is probably what should be done.

larsgrefer commented 1 week ago

Using a Spring MVC Controller is an easy solution, but a minimal JoinFaces application does not include Spring MVC. Including Spring MVC only for the welcome file redirect seems overkill.

I've implemented a solution using a servlet for the meantime: https://github.com/joinfaces/joinfaces-gradle-jar-example/commit/f0ac4db89b92c520889edb71723e8ff7dd773343#diff-2db5361837c74e2115670afe83ee059ca93915e854e8417acf6506a59e74881b