├── .gitignore ├── README.md ├── pom.xml └── src └── main ├── java └── com │ └── github │ └── bilak │ └── spring_boot_primefaces_template │ ├── configuration │ ├── Application.java │ └── ViewScope.java │ └── view │ ├── FileUploadBean.java │ └── TestBean.java ├── resources └── application.properties └── webapp ├── WEB-INF └── faces-config.xml └── view └── fileupload.xhtml /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | spring-boot-primefaces-template.iml -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-primefaces-template 2 | 3 | Simple template application for Primefaces (5.2) on Spring-boot (1.2.3).
4 | Also configured fileupload and provided one page with this functionality. 5 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.github.bilak 8 | spring-boot-primefaces-template 9 | 1.0-SNAPSHOT 10 | war 11 | 12 | 13 | 14 | UTF-8 15 | UTF-8 16 | 1.8 17 | 1.8 18 | 1.8 19 | 1.2.4.RELEASE 20 | 8.0.20 21 | 22 | 23 | 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | ${spring-boot.version} 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-tomcat 34 | ${spring-boot.version} 35 | provided 36 | 37 | 38 | 39 | 40 | org.apache.tomcat.embed 41 | tomcat-embed-core 42 | ${tomcat.version} 43 | provided 44 | 45 | 46 | org.apache.tomcat.embed 47 | tomcat-embed-logging-juli 48 | ${tomcat.version} 49 | provided 50 | 51 | 52 | org.apache.tomcat.embed 53 | tomcat-embed-jasper 54 | ${tomcat.version} 55 | provided 56 | 57 | 58 | javax.servlet 59 | jstl 60 | 1.2 61 | 62 | 63 | 64 | 65 | 66 | com.sun.faces 67 | jsf-api 68 | 2.2.12 69 | 70 | 71 | com.sun.faces 72 | jsf-impl 73 | 2.2.12 74 | 75 | 76 | org.primefaces 77 | primefaces 78 | 5.2 79 | 80 | 81 | org.primefaces.themes 82 | all-themes 83 | 1.0.10 84 | 85 | 86 | net.bootsfaces 87 | bootsfaces 88 | 0.7.0 89 | 90 | 91 | 92 | 93 | commons-io 94 | commons-io 95 | 2.2 96 | 97 | 98 | 99 | commons-fileupload 100 | commons-fileupload 101 | 1.3 102 | 103 | 104 | 105 | 106 | org.springframework.boot 107 | spring-boot-starter-test 108 | ${spring-boot.version} 109 | test 110 | 111 | 112 | 113 | 114 | application 115 | 116 | 117 | org.springframework.boot 118 | spring-boot-maven-plugin 119 | ${spring-boot.version} 120 | 121 | true 122 | 123 | -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 124 | 125 | com.github.bilak.spring_boot_primefaces_template.configuration.Application 126 | 127 | 128 | 129 | org.apache.maven.plugins 130 | maven-war-plugin 131 | 2.6 132 | 133 | false 134 | 135 | 136 | 137 | 138 | 139 | 140 | tomcat-localhost 141 | 142 | 143 | tomcat 144 | 145 | 146 | 147 | 148 | 149 | org.apache.maven.plugins 150 | maven-war-plugin 151 | 2.6 152 | 153 | WEB-INF/lib/tomcat*.jar 154 | false 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | prime-repo 165 | Prime Repo 166 | http://repository.primefaces.org 167 | 168 | 169 | 170 | 171 | -------------------------------------------------------------------------------- /src/main/java/com/github/bilak/spring_boot_primefaces_template/configuration/Application.java: -------------------------------------------------------------------------------- 1 | package com.github.bilak.spring_boot_primefaces_template.configuration; 2 | 3 | import org.primefaces.webapp.filter.FileUploadFilter; 4 | import org.springframework.beans.factory.config.CustomScopeConfigurer; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.boot.context.embedded.FilterRegistrationBean; 9 | import org.springframework.boot.context.embedded.ServletContextInitializer; 10 | import org.springframework.boot.context.embedded.ServletRegistrationBean; 11 | import org.springframework.boot.context.web.SpringBootServletInitializer; 12 | import org.springframework.context.annotation.Bean; 13 | import org.springframework.context.annotation.ComponentScan; 14 | 15 | import javax.faces.webapp.FacesServlet; 16 | import javax.servlet.DispatcherType; 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | 20 | /** 21 | * Created by lvasek on 17/04/15. 22 | */ 23 | @SpringBootApplication 24 | @EnableAutoConfiguration 25 | @ComponentScan(basePackages = {"com.github.bilak.spring_boot_primefaces_template.view"}) 26 | public class Application extends SpringBootServletInitializer { 27 | 28 | 29 | public static void main(String[] args) { 30 | SpringApplication app = new SpringApplication(Application.class); 31 | app.run(args); 32 | } 33 | 34 | @Bean 35 | public ServletRegistrationBean facesServletRegistraiton() { 36 | ServletRegistrationBean registration = new ServletRegistrationBean(new FacesServlet(), new String[]{"*.xhtml"}); 37 | registration.setName("Faces Servlet"); 38 | registration.setLoadOnStartup(1); 39 | return registration; 40 | } 41 | 42 | 43 | @Bean 44 | public FilterRegistrationBean facesUploadFilterRegistration() { 45 | FilterRegistrationBean registrationBean = new FilterRegistrationBean(new FileUploadFilter(), facesServletRegistraiton()); 46 | registrationBean.setName("PrimeFaces FileUpload Filter"); 47 | registrationBean.addUrlPatterns("/*"); 48 | registrationBean.setDispatcherTypes(DispatcherType.FORWARD, DispatcherType.REQUEST); 49 | return registrationBean; 50 | } 51 | 52 | @Bean 53 | public ServletContextInitializer servletContextInitializer() { 54 | return servletContext -> { 55 | servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString()); 56 | servletContext.setInitParameter("primefaces.THEME", "bootstrap"); 57 | servletContext.setInitParameter("primefaces.CLIENT_SIDE_VALIDATION", Boolean.TRUE.toString()); 58 | servletContext.setInitParameter("javax.faces.FACELETS_SKIP_COMMENTS", Boolean.TRUE.toString()); 59 | servletContext.setInitParameter("primefaces.FONT_AWESOME", Boolean.TRUE.toString()); 60 | servletContext.setInitParameter("primefaces.UPLOADER", "commons"); 61 | }; 62 | } 63 | 64 | @Bean 65 | public static CustomScopeConfigurer customScopeConfigurer(){ 66 | CustomScopeConfigurer configurer = new CustomScopeConfigurer(); 67 | Map scopes = new HashMap(); 68 | scopes.put("view", new ViewScope()); 69 | configurer.setScopes(scopes); 70 | return configurer; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/github/bilak/spring_boot_primefaces_template/configuration/ViewScope.java: -------------------------------------------------------------------------------- 1 | package com.github.bilak.spring_boot_primefaces_template.configuration; 2 | 3 | import org.springframework.beans.factory.ObjectFactory; 4 | import org.springframework.beans.factory.config.Scope; 5 | 6 | import javax.faces.context.FacesContext; 7 | import java.util.Map; 8 | 9 | /** 10 | * Created by lvasek on 29/04/15. 11 | */ 12 | // copied from https://cagataycivici.wordpress.com/2010/02/17/port-jsf-2-0s-viewscope-to-spring-3-0/ 13 | public class ViewScope implements Scope { 14 | @Override 15 | public Object get(String name, ObjectFactory objectFactory) { 16 | FacesContext context = FacesContext.getCurrentInstance(); 17 | if (context.getViewRoot() != null) { 18 | Map viewMap = context.getViewRoot().getViewMap(); 19 | 20 | if (viewMap.containsKey(name)) { 21 | return viewMap.get(name); 22 | } else { 23 | Object object = objectFactory.getObject(); 24 | viewMap.put(name, object); 25 | 26 | return object; 27 | } 28 | } 29 | return null; 30 | } 31 | 32 | @Override 33 | public Object remove(String name) { 34 | return FacesContext.getCurrentInstance().getViewRoot().getViewMap().remove(name); 35 | } 36 | 37 | @Override 38 | public void registerDestructionCallback(String s, Runnable runnable) { 39 | 40 | } 41 | 42 | @Override 43 | public Object resolveContextualObject(String s) { 44 | return null; 45 | } 46 | 47 | @Override 48 | public String getConversationId() { 49 | return null; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/github/bilak/spring_boot_primefaces_template/view/FileUploadBean.java: -------------------------------------------------------------------------------- 1 | package com.github.bilak.spring_boot_primefaces_template.view; 2 | 3 | import org.primefaces.event.FileUploadEvent; 4 | import org.primefaces.model.UploadedFile; 5 | import org.springframework.context.annotation.Scope; 6 | import org.springframework.stereotype.Component; 7 | 8 | import javax.faces.application.FacesMessage; 9 | import javax.faces.context.FacesContext; 10 | import java.io.Serializable; 11 | 12 | /** 13 | * Created by lvasek on 17/04/15. 14 | */ 15 | @Component("fileUploadBean") 16 | @Scope("request") 17 | public class FileUploadBean implements Serializable{ 18 | 19 | private UploadedFile file; 20 | 21 | public UploadedFile getFile() { 22 | return file; 23 | } 24 | 25 | public void setFile(UploadedFile file) { 26 | this.file = file; 27 | } 28 | 29 | 30 | public String handleFileUpload(FileUploadEvent fileUploadEvent){ 31 | this.file = fileUploadEvent.getFile(); 32 | if (file!=null) 33 | FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("File uploaded successfully")); 34 | else 35 | FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,"Warning file was not uploaded", "Size of file is null. Is this ok? ")); 36 | 37 | return null; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/github/bilak/spring_boot_primefaces_template/view/TestBean.java: -------------------------------------------------------------------------------- 1 | package com.github.bilak.spring_boot_primefaces_template.view; 2 | 3 | import org.springframework.context.annotation.Scope; 4 | import org.springframework.stereotype.Component; 5 | 6 | import javax.annotation.PostConstruct; 7 | import java.io.Serializable; 8 | 9 | /** 10 | * Created by lvasek on 09/06/15. 11 | */ 12 | @Component("testBean") 13 | @Scope("view") 14 | public class TestBean implements Serializable { 15 | 16 | TestPojo testPojo = new TestPojo(); 17 | 18 | boolean edit = false; 19 | 20 | public class TestPojo{ 21 | boolean trueFalse = true; 22 | String testText = "testing this"; 23 | 24 | public boolean isTrueFalse() { 25 | return trueFalse; 26 | } 27 | 28 | public void setTrueFalse(boolean trueFalse) { 29 | this.trueFalse = trueFalse; 30 | } 31 | 32 | public String getTestText() { 33 | return testText; 34 | } 35 | 36 | public void setTestText(String testText) { 37 | this.testText = testText; 38 | } 39 | } 40 | 41 | @PostConstruct 42 | public void init(){ 43 | System.out.println(testPojo.trueFalse); 44 | } 45 | 46 | public TestPojo getTestPojo() { 47 | return testPojo; 48 | } 49 | 50 | public void setTestPojo(TestPojo testPojo) { 51 | this.testPojo = testPojo; 52 | } 53 | 54 | public boolean isEdit() { 55 | return edit; 56 | } 57 | 58 | public void setEdit(boolean edit) { 59 | this.edit = edit; 60 | } 61 | 62 | public void editActionListener(){ 63 | this.edit = true; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilak/spring-boot-primefaces-template/6ccce27b0fecff23dee101b880089932d5be28a6/src/main/resources/application.properties -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/faces-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | org.springframework.web.jsf.el.SpringBeanFacesELResolver 8 | 9 | -------------------------------------------------------------------------------- /src/main/webapp/view/fileupload.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | FILE UPLOAD 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 31 | 32 | 33 | 34 | --------------------------------------------------------------------------------