Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add "welcome-file" configuration example #101

Open
kartu opened this issue Sep 18, 2024 · 3 comments
Open

Please add "welcome-file" configuration example #101

kartu opened this issue Sep 18, 2024 · 3 comments

Comments

@kartu
Copy link

kartu commented Sep 18, 2024

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
Copy link
Member

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

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

larsgrefer added a commit to joinfaces/joinfaces-gradle-war-example that referenced this issue Oct 2, 2024
larsgrefer added a commit that referenced this issue Oct 2, 2024
@kartu
Copy link
Author

kartu commented Oct 11, 2024

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.

  1. 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
Copy link
Member

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: f0ac4db#diff-2db5361837c74e2115670afe83ee059ca93915e854e8417acf6506a59e74881b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants