package com.github.persapiens.jsfboot.omnifaces;


import javax.servlet.DispatcherType;
import org.omnifaces.filter.CharacterEncodingFilter;
import com.github.persapiens.jsfboot.javaxfaces.JavaxFacesSpringBootAutoConfiguration;
import javax.servlet.ServletContainerInitializer;
import org.omnifaces.facesviews.FacesViewsInitializer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.boot.context.embedded.ServletContextInitializer;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(OmnifacesProperties.class)
@ConditionalOnClass({CharacterEncodingFilter.class})
@AutoConfigureBefore(JavaxFacesSpringBootAutoConfiguration.class)
@ConditionalOnWebApplication
public class OmnifacesSpringBootAutoConfiguration {

	@Autowired
	private OmnifacesProperties omnifacesProperties;

    public ServletContainerInitializer getServletContainerInitializer()
    {
        return new FacesViewsInitializer();
    }
    
    public String getAnotherFacesConfig() {
        return null;
    }
    
    public boolean isExcludeScopedAnnotations() {
        return true;
    }
    
    @Bean
    public ServletContextInitializer omnifacesServletContextInitializer()
    {
        return new OmnifacesServletContextInitializer(omnifacesProperties);
    }
    
    /**
     * Register omnifaces filter to solve primefaces encoding problem
     * @return characterEncodingFilter
     */ 
    @Bean
    public FilterRegistrationBean characterEncodingFilter() {
        FilterRegistrationBean result = new FilterRegistrationBean();
        result.setName("characterEncodingFilter");
        result.setFilter(new CharacterEncodingFilter());
        result.setDispatcherTypes(DispatcherType.FORWARD, DispatcherType.REQUEST
            , DispatcherType.INCLUDE, DispatcherType.ASYNC
            , DispatcherType.ERROR);
        result.setMatchAfter(true);
        result.addUrlPatterns("/*");
        
        return result;
    }
}

@@ -48,98 +48,8 @@
 ;%0A%0A%0A
-import javax.servlet.DispatcherType;%0Aimport org.omnifaces.filter.CharacterEncodingFilter;%0A
 impo
@@ -135,58 +135,8 @@
 on;%0A
-import javax.servlet.ServletContainerInitializer;%0A
 impo
@@ -481,81 +481,8 @@
 on;%0A
-import org.springframework.boot.context.embedded.FilterRegistrationBean;%0A
 impo
@@ -843,37 +843,35 @@
 nClass(%7B
-CharacterEncodingFilt
+FacesViewsInitializ
 er.class
@@ -1087,1133 +1087,177 @@
 es;%0A
-%0A    public ServletContainerInitializer getServletContainerInitializer()%0A    %7B%0A        return new FacesViewsInitializer();%0A    %7D%0A    %0A    public String getAnotherFacesConfig() %7B%0A        return null;%0A    %7D%0A    %0A    public boolean isExcludeScopedAnnotations() %7B%0A        return true;%0A    %7D%0A    %0A    @Bean%0A    public ServletContextInitializer omnifacesServletContextInitializer()%0A    %7B%0A        return new OmnifacesServletContextInitializer(omnifacesProperties);%0A    %7D%0A    %0A    /**%0A     * Register omnifaces filter to solve primefaces encoding problem%0A     * @return characterEncodingFilter%0A     */ %0A    @Bean%0A    public FilterRegistrationBean characterEncodingFilter() %7B%0A        FilterRegistrationBean result = new FilterRegistrationBean();%0A        result.setName(%22characterEncodingFilter%22);%0A        result.setFilter(new CharacterEncodingFilter());%0A        result.setDispatcherTypes(DispatcherType.FORWARD, DispatcherType.REQUEST%0A            , DispatcherType.INCLUDE, DispatcherType.ASYNC%0A            , DispatcherType.ERROR);%0A        result.setMatchAfter(true);%0A        result.addUrlPatterns(%22/*%22);%0A        %0A        return result
+    %0A    @Bean%0A    public ServletContextInitializer omnifacesServletContextInitializer()%0A    %7B%0A        return new OmnifacesServletContextInitializer(omnifacesProperties)
 ;%0A  

fix #75 removed Omnifaces CharacterEncodingFilter in favor of Spring Web CharacterEncodingFilter