1

I am trying to start my new project using spring webmvc (version 4.1.6) with primefaces (version 5.2) I am able start up the project, however when trying to acces css or other resources the urls looks like: http://localhost:8080/rais/public//javax.faces.resource/theme.css?ln=primefaces-aristo and results in a 404. The part: http://localhost:8080/rais/public/ looks as expected.

My configuration:

@Configuration
@EnableTransactionManagement
@EnableSpringConfigured
@EnableWebMvc
public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

@Override
public void onStartup(ServletContext servletContext) throws ServletException {

    //Set init params       
    // Use JSF view templates saved as *.xhtml, for use with Facelets
    servletContext.setInitParameter("javax.faces.DEFAULT_SUFFIX", ".xhtml");



    servletContext.setInitParameter("javax.faces.FACELETS_VIEW_MAPPINGS", "*.xhtml");



    ServletRegistration.Dynamic facesServlet = servletContext.addServlet("Faces Servlet", javax.faces.webapp.FacesServlet.class);
    facesServlet.setLoadOnStartup(1);
    facesServlet.addMapping("*.xhtml");

    ServletRegistration.Dynamic registration = servletContext.addServlet("dsp", new DispatcherServlet());
    registration.setInitParameter("contextConfigLocation", "");
    registration.setLoadOnStartup(1);
    registration.addMapping("/");


    servletContext.addListener(ConfigureListener.class);
    servletContext.addListener(org.springframework.web.context.request.RequestContextListener.class);

    //Add OpenEntityManagerInViewFilter Filter
    servletContext.addFilter("openEntityManagerInViewFilter", OpenEntityManagerInViewFilter.class).addMappingForUrlPatterns(null, true, "/*");


    super.onStartup(servletContext);
}

WebMVC configuration:

@Configuration
@EnableWebMvc

public class WebMvcConfig extends WebMvcConfigurerAdapter {

@Bean
ViewResolver viewResolver() {
    UrlBasedViewResolver resolver = new UrlBasedViewResolver();
    resolver.setViewClass(org.springframework.faces.mvc.JsfView.class);
    resolver.setPrefix("/WEB-INF");
    resolver.setSuffix(".xhtml");
    return resolver;

}

faces-config.xml (ani hint in moving this to java config also greatly appreciated)

    <application>
        <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
        <action-listener>org.primefaces.application.DialogActionListener</action-listener>
        <navigation-handler>org.primefaces.application.DialogNavigationHandler</navigation-handler>
        <view-handler>org.primefaces.application.DialogViewHandler</view-handler>
    </application>

Any help is greatly appreciated. Please ask if additional information is required:

bwright
  • 896
  • 11
  • 29
  • 1
    Why does everyone keep trying to mix Spring MVC with JSF? What makes Spring MVC so special that it seemingly must be used together with its full competitor JSF? Or is every Spring starter confusing/mixing "Spring DI/IoC" with "Spring MVC"? Still can't get my head around it. – BalusC May 04 '15 at 07:59
  • 1
    @BalusC: or is Spring MVC so limited that they want to add JSF ;-) – Kukeltje May 04 '15 at 08:02
  • @BalusC i suggest to create some example project on github so that people could learn from it. I'm surprised that primefaces has no example "startup" project ... So people spend around reading random blogs and getting wrong information's (obviously) – anotherUser May 04 '15 at 13:01
  • @jNick: when I google "primefaces spring integration example" I get thousands of hits. – BalusC May 04 '15 at 13:05
  • 1
    Yes there are thousands of posts. Which i have looked through (some of them) but could not find a solution to my problem. Why would one weant to combine spring-mvc with jsf? in my case iwant to be able to use the nice primefaces framework. – bwright May 04 '15 at 13:16
  • PrimeFaces is not a Spring MVC tag library, it's a JSF component library. PrimeFaces uses jQuery UI for the UI, so you could also just use jQuery UI right away. Here's some food for read: http://stackoverflow.com/q/4421839 and http://stackoverflow.com/q/18744910 – BalusC May 04 '15 at 15:16

1 Answers1

0

Ok changed the UrlBasedViewResolver(); to a InternalResourceViewResolver(); now it seems to be working.

bwright
  • 896
  • 11
  • 29
  • which class did you use for the view class then? if I continue to use this: resolver.setViewClass(org.springframework.faces.mvc.JsfView.class); then it crashed because the JsfView class is not compatible with the InternalResourceViewResolver – Sloth Jul 02 '15 at 07:54