diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9fb5886 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,23 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +indent_style = tab +indent_size = 2 +continuation_indent_size = 2 + +[*.yml] +indent_style = space +indent_size = 2 +end_of_line = lf + +[package.json] +indent_style = space +indent_size = 2 +end_of_line = lf diff --git a/.gitignore b/.gitignore index d2a4444..776d134 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,7 @@ .idea -spring-boot-primefaces-template.iml \ No newline at end of file +*.iml +target/ +build/ +.gradle/ +*.log +out/ diff --git a/README.md b/README.md index 0e974c8..1eca6be 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,13 @@ -# spring-boot-primefaces-template +Simple example application for **Primefaces (6.0)** running on **Spring-boot 2** -Simple template application for Primefaces (5.2) on Spring-boot (1.2.3).
-Also configured fileupload and provided one page with this functionality. +* File Upload +* Realtime Database Insertion + +### Running It + +```bash +$ ./gradlew bootRun +... +Tomcat initialized with port(s): 9091 (http) +``` +Then access contact list page: http://localhost:9091/view/contact-list.xhtml diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..2ecee44 --- /dev/null +++ b/build.gradle @@ -0,0 +1,55 @@ +plugins { + id 'org.springframework.boot' version '2.1.3.RELEASE' + id 'java' +} + +repositories { + mavenLocal() + mavenCentral() + maven { url = 'http://repository.primefaces.org' } +} + +sourceCompatibility = JavaVersion.VERSION_11 + +configurations { + provided +} + +sourceSets { + main { + compileClasspath += configurations.provided + test.compileClasspath += configurations.provided + test.runtimeClasspath += configurations.provided + } +} + +allprojects { + tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' + } +} + +dependencies { + + compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion + compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: springBootVersion + compile group: "org.apache.tomcat.embed", name: "tomcat-embed-jasper", version: '9.0.16' + compile group: 'jstl', name: 'jstl', version: jstlVersion + + // JSF + compile group: 'com.sun.faces', name: 'jsf-api', version: jsfVersion + compile group: 'com.sun.faces', name: 'jsf-impl', version: jsfVersion + + compile group: 'org.primefaces', name: 'primefaces', version: primefacesVersion + compile group: 'org.primefaces.themes', name: 'bootstrap', version: '1.0.8' + compile group: 'net.bootsfaces', name: 'bootsfaces', version: '0.7.0' + + // commons + compile group: 'commons-io', name: 'commons-io', version: '2.4' + compile group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.1' + + testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion + testCompile group: 'junit', name: 'junit', version: '4.12' + testCompile group: 'org.mockito', name: 'mockito-core', version: '2.24.0' + +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..d5878cd --- /dev/null +++ b/gradle.properties @@ -0,0 +1,4 @@ +jsfVersion=2.2.12 +jstlVersion=1.2 +primefacesVersion=6.0 +springBootVersion=2.1.3.RELEASE diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..ca78035 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..6cf387f --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri Aug 12 23:38:47 BRT 2016 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..27309d9 --- /dev/null +++ b/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..f6d5974 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 9a48097..0000000 --- a/pom.xml +++ /dev/null @@ -1,170 +0,0 @@ - - - 4.0.0 - - com.github.bilak - spring-boot-primefaces-template - 1.0-SNAPSHOT - war - - - - UTF-8 - UTF-8 - 1.8 - 1.8 - 1.8 - 1.2.4.RELEASE - 8.0.20 - - - - - - - org.springframework.boot - spring-boot-starter-web - ${spring-boot.version} - - - org.springframework.boot - spring-boot-starter-tomcat - ${spring-boot.version} - provided - - - - - org.apache.tomcat.embed - tomcat-embed-core - ${tomcat.version} - provided - - - org.apache.tomcat.embed - tomcat-embed-logging-juli - ${tomcat.version} - provided - - - org.apache.tomcat.embed - tomcat-embed-jasper - ${tomcat.version} - provided - - - javax.servlet - jstl - 1.2 - - - - - - com.sun.faces - jsf-api - 2.2.12 - - - com.sun.faces - jsf-impl - 2.2.12 - - - org.primefaces - primefaces - 5.2 - - - org.primefaces.themes - all-themes - 1.0.10 - - - net.bootsfaces - bootsfaces - 0.7.0 - - - - - commons-io - commons-io - 2.2 - - - - commons-fileupload - commons-fileupload - 1.3 - - - - - org.springframework.boot - spring-boot-starter-test - ${spring-boot.version} - test - - - - - application - - - org.springframework.boot - spring-boot-maven-plugin - ${spring-boot.version} - - true - - -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 - - com.github.bilak.spring_boot_primefaces_template.configuration.Application - - - - org.apache.maven.plugins - maven-war-plugin - 2.6 - - false - - - - - - - tomcat-localhost - - - tomcat - - - - - - org.apache.maven.plugins - maven-war-plugin - 2.6 - - WEB-INF/lib/tomcat*.jar - false - - - - - - - - - - prime-repo - Prime Repo - http://repository.primefaces.org - - - - diff --git a/src/main/java/com/github/bilak/spring_boot_primefaces_template/configuration/Application.java b/src/main/java/com/github/bilak/spring_boot_primefaces_template/configuration/Application.java deleted file mode 100644 index f7881fa..0000000 --- a/src/main/java/com/github/bilak/spring_boot_primefaces_template/configuration/Application.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.github.bilak.spring_boot_primefaces_template.configuration; - -import org.primefaces.webapp.filter.FileUploadFilter; -import org.springframework.beans.factory.config.CustomScopeConfigurer; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.context.embedded.FilterRegistrationBean; -import org.springframework.boot.context.embedded.ServletContextInitializer; -import org.springframework.boot.context.embedded.ServletRegistrationBean; -import org.springframework.boot.context.web.SpringBootServletInitializer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; - -import javax.faces.webapp.FacesServlet; -import javax.servlet.DispatcherType; -import java.util.HashMap; -import java.util.Map; - -/** - * Created by lvasek on 17/04/15. - */ -@SpringBootApplication -@EnableAutoConfiguration -@ComponentScan(basePackages = {"com.github.bilak.spring_boot_primefaces_template.view"}) -public class Application extends SpringBootServletInitializer { - - - public static void main(String[] args) { - SpringApplication app = new SpringApplication(Application.class); - app.run(args); - } - - @Bean - public ServletRegistrationBean facesServletRegistraiton() { - ServletRegistrationBean registration = new ServletRegistrationBean(new FacesServlet(), new String[]{"*.xhtml"}); - registration.setName("Faces Servlet"); - registration.setLoadOnStartup(1); - return registration; - } - - - @Bean - public FilterRegistrationBean facesUploadFilterRegistration() { - FilterRegistrationBean registrationBean = new FilterRegistrationBean(new FileUploadFilter(), facesServletRegistraiton()); - registrationBean.setName("PrimeFaces FileUpload Filter"); - registrationBean.addUrlPatterns("/*"); - registrationBean.setDispatcherTypes(DispatcherType.FORWARD, DispatcherType.REQUEST); - return registrationBean; - } - - @Bean - public ServletContextInitializer servletContextInitializer() { - return servletContext -> { - servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString()); - servletContext.setInitParameter("primefaces.THEME", "bootstrap"); - servletContext.setInitParameter("primefaces.CLIENT_SIDE_VALIDATION", Boolean.TRUE.toString()); - servletContext.setInitParameter("javax.faces.FACELETS_SKIP_COMMENTS", Boolean.TRUE.toString()); - servletContext.setInitParameter("primefaces.FONT_AWESOME", Boolean.TRUE.toString()); - servletContext.setInitParameter("primefaces.UPLOADER", "commons"); - }; - } - - @Bean - public static CustomScopeConfigurer customScopeConfigurer(){ - CustomScopeConfigurer configurer = new CustomScopeConfigurer(); - Map scopes = new HashMap(); - scopes.put("view", new ViewScope()); - configurer.setScopes(scopes); - return configurer; - } -} diff --git a/src/main/java/com/github/bilak/spring_boot_primefaces_template/configuration/ViewScope.java b/src/main/java/com/github/bilak/spring_boot_primefaces_template/configuration/ViewScope.java deleted file mode 100644 index 164d4d4..0000000 --- a/src/main/java/com/github/bilak/spring_boot_primefaces_template/configuration/ViewScope.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.github.bilak.spring_boot_primefaces_template.configuration; - -import org.springframework.beans.factory.ObjectFactory; -import org.springframework.beans.factory.config.Scope; - -import javax.faces.context.FacesContext; -import java.util.Map; - -/** - * Created by lvasek on 29/04/15. - */ -// copied from https://cagataycivici.wordpress.com/2010/02/17/port-jsf-2-0s-viewscope-to-spring-3-0/ -public class ViewScope implements Scope { - @Override - public Object get(String name, ObjectFactory objectFactory) { - FacesContext context = FacesContext.getCurrentInstance(); - if (context.getViewRoot() != null) { - Map viewMap = context.getViewRoot().getViewMap(); - - if (viewMap.containsKey(name)) { - return viewMap.get(name); - } else { - Object object = objectFactory.getObject(); - viewMap.put(name, object); - - return object; - } - } - return null; - } - - @Override - public Object remove(String name) { - return FacesContext.getCurrentInstance().getViewRoot().getViewMap().remove(name); - } - - @Override - public void registerDestructionCallback(String s, Runnable runnable) { - - } - - @Override - public Object resolveContextualObject(String s) { - return null; - } - - @Override - public String getConversationId() { - return null; - } -} diff --git a/src/main/java/com/github/bilak/spring_boot_primefaces_template/view/FileUploadBean.java b/src/main/java/com/github/bilak/spring_boot_primefaces_template/view/FileUploadBean.java deleted file mode 100644 index a77be07..0000000 --- a/src/main/java/com/github/bilak/spring_boot_primefaces_template/view/FileUploadBean.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.github.bilak.spring_boot_primefaces_template.view; - -import org.primefaces.event.FileUploadEvent; -import org.primefaces.model.UploadedFile; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; - -import javax.faces.application.FacesMessage; -import javax.faces.context.FacesContext; -import java.io.Serializable; - -/** - * Created by lvasek on 17/04/15. - */ -@Component("fileUploadBean") -@Scope("request") -public class FileUploadBean implements Serializable{ - - private UploadedFile file; - - public UploadedFile getFile() { - return file; - } - - public void setFile(UploadedFile file) { - this.file = file; - } - - - public String handleFileUpload(FileUploadEvent fileUploadEvent){ - this.file = fileUploadEvent.getFile(); - if (file!=null) - FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("File uploaded successfully")); - else - FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,"Warning file was not uploaded", "Size of file is null. Is this ok? ")); - - return null; - } -} diff --git a/src/main/java/com/github/bilak/spring_boot_primefaces_template/view/TestBean.java b/src/main/java/com/github/bilak/spring_boot_primefaces_template/view/TestBean.java deleted file mode 100644 index e48fd42..0000000 --- a/src/main/java/com/github/bilak/spring_boot_primefaces_template/view/TestBean.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.github.bilak.spring_boot_primefaces_template.view; - -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; - -import javax.annotation.PostConstruct; -import java.io.Serializable; - -/** - * Created by lvasek on 09/06/15. - */ -@Component("testBean") -@Scope("view") -public class TestBean implements Serializable { - - TestPojo testPojo = new TestPojo(); - - boolean edit = false; - - public class TestPojo{ - boolean trueFalse = true; - String testText = "testing this"; - - public boolean isTrueFalse() { - return trueFalse; - } - - public void setTrueFalse(boolean trueFalse) { - this.trueFalse = trueFalse; - } - - public String getTestText() { - return testText; - } - - public void setTestText(String testText) { - this.testText = testText; - } - } - - @PostConstruct - public void init(){ - System.out.println(testPojo.trueFalse); - } - - public TestPojo getTestPojo() { - return testPojo; - } - - public void setTestPojo(TestPojo testPojo) { - this.testPojo = testPojo; - } - - public boolean isEdit() { - return edit; - } - - public void setEdit(boolean edit) { - this.edit = edit; - } - - public void editActionListener(){ - this.edit = true; - } -} diff --git a/src/main/java/com/github/springprimefaces/Application.java b/src/main/java/com/github/springprimefaces/Application.java new file mode 100644 index 0000000..7210c1c --- /dev/null +++ b/src/main/java/com/github/springprimefaces/Application.java @@ -0,0 +1,51 @@ +package com.github.springprimefaces; + +import com.github.springprimefaces.configuration.ViewScope; +import org.springframework.beans.factory.config.CustomScopeConfigurer; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.ServletContextInitializer; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; + +import javax.faces.webapp.FacesServlet; +import java.util.HashMap; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + + @Bean + public static CustomScopeConfigurer customScopeConfigurer() { + + final var scopes = new HashMap(); + scopes.put("view", new ViewScope()); + + final CustomScopeConfigurer configurer = new CustomScopeConfigurer(); + configurer.setScopes(scopes); + return configurer; + } + + @Bean + public ServletRegistrationBean facesServletRegistraiton() { + final var registration = new ServletRegistrationBean<>(new FacesServlet(), "*.xhtml"); + registration.setName("Faces Servlet"); + registration.setLoadOnStartup(1); + return registration; + } + + @Bean + public ServletContextInitializer servletContextInitializer() { + return servletContext -> { + servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString()); + servletContext.setInitParameter("primefaces.THEME", "bootstrap"); + servletContext.setInitParameter("primefaces.CLIENT_SIDE_VALIDATION", Boolean.TRUE.toString()); + servletContext.setInitParameter("javax.faces.FACELETS_SKIP_COMMENTS", Boolean.TRUE.toString()); + servletContext.setInitParameter("primefaces.FONT_AWESOME", Boolean.TRUE.toString()); + servletContext.setInitParameter("primefaces.UPLOADER", "commons"); + }; + } +} diff --git a/src/main/java/com/github/springprimefaces/configuration/MyComponent.java b/src/main/java/com/github/springprimefaces/configuration/MyComponent.java new file mode 100644 index 0000000..b96a548 --- /dev/null +++ b/src/main/java/com/github/springprimefaces/configuration/MyComponent.java @@ -0,0 +1,13 @@ +package com.github.springprimefaces.configuration; + +import org.springframework.stereotype.Component; + +/** + * @author elvis + * @version $Revision: $
+ * $Id: $ + * @since 8/12/16 10:39 AM + */ +@Component +public class MyComponent { +} diff --git a/src/main/java/com/github/springprimefaces/configuration/ViewScope.java b/src/main/java/com/github/springprimefaces/configuration/ViewScope.java new file mode 100644 index 0000000..5603083 --- /dev/null +++ b/src/main/java/com/github/springprimefaces/configuration/ViewScope.java @@ -0,0 +1,51 @@ +package com.github.springprimefaces.configuration; + +import org.springframework.beans.factory.ObjectFactory; +import org.springframework.beans.factory.config.Scope; + +import javax.faces.context.FacesContext; +import java.util.Map; + +/** + * Created by lvasek on 29/04/15. + */ +// copied from https://cagataycivici.wordpress.com/2010/02/17/port-jsf-2-0s-viewscope-to-spring-3-0/ +public class ViewScope implements Scope { + @Override + public Object get(String name, ObjectFactory objectFactory) { + FacesContext context = FacesContext.getCurrentInstance(); + if (context.getViewRoot() != null) { + Map viewMap = context.getViewRoot().getViewMap(); + + if (viewMap.containsKey(name)) { + return viewMap.get(name); + } else { + Object object = objectFactory.getObject(); + viewMap.put(name, object); + + return object; + } + } + return null; + } + + @Override + public Object remove(String name) { + return FacesContext.getCurrentInstance().getViewRoot().getViewMap().remove(name); + } + + @Override + public void registerDestructionCallback(String s, Runnable runnable) { + + } + + @Override + public Object resolveContextualObject(String s) { + return null; + } + + @Override + public String getConversationId() { + return null; + } +} diff --git a/src/main/java/com/github/springprimefaces/controller/ContactListController.java b/src/main/java/com/github/springprimefaces/controller/ContactListController.java new file mode 100644 index 0000000..483e922 --- /dev/null +++ b/src/main/java/com/github/springprimefaces/controller/ContactListController.java @@ -0,0 +1,42 @@ +package com.github.springprimefaces.controller; + +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Controller; + +import javax.faces.bean.ManagedBean; +import java.util.ArrayList; +import java.util.List; + +/** + * @author elvis + * @version $Revision: $
+ * $Id: $ + * @since 8/12/16 10:57 AM + */ + +@ManagedBean +@Scope("view") +@Controller("ContactListController") +public class ContactListController { + + List contacts = new ArrayList<>(); + private String currentContact = "New Contact"; + + public void addContact(String contact) { + contacts.add(contact); + this.currentContact = ""; + } + + public List getContacts() { + return contacts; + } + + public String getCurrentContact() { + return currentContact; + } + + public void setCurrentContact(String currentContact) { + this.currentContact = currentContact; + } + +} diff --git a/src/main/java/com/github/springprimefaces/controller/FileUploadBean.java b/src/main/java/com/github/springprimefaces/controller/FileUploadBean.java new file mode 100644 index 0000000..c25d7b3 --- /dev/null +++ b/src/main/java/com/github/springprimefaces/controller/FileUploadBean.java @@ -0,0 +1,39 @@ +package com.github.springprimefaces.controller; + +import org.primefaces.event.FileUploadEvent; +import org.primefaces.model.UploadedFile; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import javax.faces.application.FacesMessage; +import javax.faces.context.FacesContext; +import java.io.Serializable; + +/** + * Created by lvasek on 17/04/15. + */ +@Component("fileUploadBean") +@Scope("request") +public class FileUploadBean implements Serializable { + + private UploadedFile file; + + public UploadedFile getFile() { + return file; + } + + public void setFile(UploadedFile file) { + this.file = file; + } + + + public String handleFileUpload(FileUploadEvent fileUploadEvent) { + this.file = fileUploadEvent.getFile(); + if (file != null) + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("File uploaded successfully")); + else + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Warning file was not uploaded", "Size of file is null. Is this ok? ")); + + return null; + } +} diff --git a/src/main/java/com/github/springprimefaces/controller/HelloController.java b/src/main/java/com/github/springprimefaces/controller/HelloController.java new file mode 100644 index 0000000..0a4b9f1 --- /dev/null +++ b/src/main/java/com/github/springprimefaces/controller/HelloController.java @@ -0,0 +1,48 @@ +package com.github.springprimefaces.controller; + +import com.github.springprimefaces.service.HelloService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.annotation.PostConstruct; +import javax.faces.bean.ManagedBean; +import java.io.Serializable; + +/** + * @author elvis + * @version $Revision: $
+ * $Id: $ + * @since 8/11/16 6:05 PM + */ +@ManagedBean(name = "helloBean") +@Scope("request") +@Controller("helloBean") +public class HelloController implements Serializable { + + private String message = "hi"; + @Autowired + private HelloService helloService; + + @PostConstruct + public void init() { + System.out.println("hi"); + } + + public String getHelloWorldMessage() { + return helloService.getHelloMessage(); + } + + public String getMessage() { + return message; + } + + @RequestMapping(value = "/hello", method = RequestMethod.GET) + @ResponseBody + public String api() { + return "hey"; + } +} diff --git a/src/main/java/com/github/springprimefaces/controller/MyController.java b/src/main/java/com/github/springprimefaces/controller/MyController.java new file mode 100644 index 0000000..e4b5b95 --- /dev/null +++ b/src/main/java/com/github/springprimefaces/controller/MyController.java @@ -0,0 +1,13 @@ +package com.github.springprimefaces.controller; + +import org.springframework.stereotype.Component; + +/** + * @author elvis + * @version $Revision: $
+ * $Id: $ + * @since 8/12/16 10:39 AM + */ +@Component +public class MyController { +} diff --git a/src/main/java/com/github/springprimefaces/controller/TestBean.java b/src/main/java/com/github/springprimefaces/controller/TestBean.java new file mode 100644 index 0000000..32e5312 --- /dev/null +++ b/src/main/java/com/github/springprimefaces/controller/TestBean.java @@ -0,0 +1,65 @@ +package com.github.springprimefaces.controller; + +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.io.Serializable; + +/** + * Created by lvasek on 09/06/15. + */ +@Component("testBean") +@Scope("view") +public class TestBean implements Serializable { + + TestPojo testPojo = new TestPojo(); + + boolean edit = false; + + @PostConstruct + public void init() { + System.out.println(testPojo.trueFalse); + } + + public TestPojo getTestPojo() { + return testPojo; + } + + public void setTestPojo(TestPojo testPojo) { + this.testPojo = testPojo; + } + + public boolean isEdit() { + return edit; + } + + public void setEdit(boolean edit) { + this.edit = edit; + } + + public void editActionListener() { + this.edit = true; + } + + public class TestPojo { + boolean trueFalse = true; + String testText = "testing this"; + + public boolean isTrueFalse() { + return trueFalse; + } + + public void setTrueFalse(boolean trueFalse) { + this.trueFalse = trueFalse; + } + + public String getTestText() { + return testText; + } + + public void setTestText(String testText) { + this.testText = testText; + } + } +} diff --git a/src/main/java/com/github/springprimefaces/service/HelloService.java b/src/main/java/com/github/springprimefaces/service/HelloService.java new file mode 100644 index 0000000..d1222f2 --- /dev/null +++ b/src/main/java/com/github/springprimefaces/service/HelloService.java @@ -0,0 +1,16 @@ +package com.github.springprimefaces.service; + +import org.springframework.stereotype.Service; + +/** + * @author elvis + * @version $Revision: $
+ * $Id: $ + * @since 8/11/16 5:50 PM + */ +@Service +public class HelloService { + public String getHelloMessage() { + return "Hello World!!!"; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e69de29..efc4d94 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -0,0 +1,4 @@ +server.context-path=/ +server.port=9091 + +encoding=ISO-8859-1 \ No newline at end of file diff --git a/src/main/webapp/view/contact-list.xhtml b/src/main/webapp/view/contact-list.xhtml new file mode 100644 index 0000000..5d2e95a --- /dev/null +++ b/src/main/webapp/view/contact-list.xhtml @@ -0,0 +1,41 @@ + + + + + + Contact List + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/view/fileupload.xhtml b/src/main/webapp/view/fileupload.xhtml index 84842db..e1eae74 100644 --- a/src/main/webapp/view/fileupload.xhtml +++ b/src/main/webapp/view/fileupload.xhtml @@ -1,33 +1,32 @@ + xmlns:h="http://java.sun.com/jsf/html" + xmlns:f="http://java.sun.com/jsf/core" + xmlns:p="http://primefaces.org/ui"> - - FILE UPLOAD - - - - + + FILE UPLOAD + + + + + + + - + + + + test + + + + + diff --git a/src/main/webapp/view/hello-world.xhtml b/src/main/webapp/view/hello-world.xhtml new file mode 100644 index 0000000..2d8a53b --- /dev/null +++ b/src/main/webapp/view/hello-world.xhtml @@ -0,0 +1,21 @@ + + + + + + Hello World + + + hey: #{helloBean.message} + + + + + + + +