layout.js - PrimeFaces.widget.Avalon not invoked - spring-boot

i using Primefaces 8.0,Springboot 2.2.5.RELEASE
and Avalon 2.1.1.
after add layout.js in template.xml, layout.js not invoke the menu on the left hand side does not work anymore. When clicking on another element from the layout-tab-menu the CSS class active is not assigned to layout-tab-submenu. The menu-resize-btn does not work anymore.
my project
template.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title><ui:insert name="title">PrimeFaces Avalon</ui:insert></title>
<f:facet name="first">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="theme-color" content="#03A9F4"/>
</f:facet>
<f:facet name="last">
<h:outputScript name="js/nanoscroller.js" library="avalon-layout" />
<h:outputScript name="js/layout.js" library="avalon-layout" />
</f:facet>
<ui:insert name="head"/>
</h:head>
<h:body>
<div class="layout-wrapper menu-layout-static">
<ui:include src="./topbar.xhtml" />
<ui:include src="menu.xhtml" />
<div class="layout-main">
<div class="layout-main-content">
<ui:insert name="content"/>
</div>
</div>
<ui:include src="./footer.xhtml" />
</div>
<p:ajaxStatus style="width:32px;height:32px;position:fixed;right:7px;bottom:7px">
<f:facet name="start">
<i class="fa fa-circle-o-notch fa-spin ajax-loader" aria-hidden="true"></i>
</f:facet>
<f:facet name="complete">
<h:outputText value="" />
</f:facet>
</p:ajaxStatus>
<h:outputStylesheet name="css/nanoscroller.css" library="avalon-layout" />
<h:outputStylesheet name="css/animate.css" library="avalon-layout" />
<h:outputStylesheet name="css/layout-blue-v4.css" library="avalon-layout" />
</h:body>
Web.xml
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
faces-config.xml
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
<el-resolver>
org.primefaces.application.exceptionhandler.PrimeExceptionHandlerELResolver
</el-resolver>
</application>
<factory>
<exception-handler-factory>
org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory
</exception-handler-factory>
</factory>
<lifecycle>
<phase-listener>org.springframework.web.jsf.DelegatingPhaseListenerMulticaster</phase-listener>
</lifecycle>
dependencies
<modelVersion>4.0.0</modelVersion>
<groupId>psa</groupId>
<artifactId>empower-web</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<name>empower-web</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.20</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.20</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>8.0</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>avalon</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0.SP1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>model</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
ServletCustom
#Bean
public ServletRegistrationBean facesServletRegistration() {
ServletRegistrationBean registration = new ServletRegistrationBean<>(new FacesServlet(), "*.xhtml");
registration.setLoadOnStartup(1);
return registration;
}
#Bean
public ServletContextInitializer servletContextInitializer() {
return servletContext -> {
servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString());
servletContext.setInitParameter("javax.faces.PROJECT_STAGE", "Development");
servletContext.setInitParameter("facelets.DEVELOPMENT", "true");
servletContext.setInitParameter("javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE", "true");
servletContext.setInitParameter("primefaces.CLIENT_SIDE_VALIDATION", "true");
servletContext.setInitParameter("primefaces.THEME", "avalon-blue-v4");
servletContext.setInitParameter("javax.faces.STATE_SAVING_METHOD", "client");
servletContext.setInitParameter("primefaces.FONT_AWESOME", "true");
servletContext.setInitParameter("primefaces.UPLOADER", "commons");
servletContext.setInitParameter("org.apache.myfaces.ERROR_HANDLING", "true");
};
}
#Bean
public ServletListenerRegistrationBean<ConfigureListener> jsfConfigureListener() {
return new ServletListenerRegistrationBean<>(new ConfigureListener());
}
Question: What am I missing to register or configure?

Related

Java EE 7, CDI 1.2, JSF 2.1, Weblogic 12.2.1 - Target Unreachable, identifier 'Controller' resolved to null [duplicate]

This question already has answers here:
Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable
(18 answers)
Closed 4 years ago.
I'm on the verge of going crazy.
My goal was to change JSF-Managed-Beans to CDI-Managed-Beans.
I thought it was just changing Annotations. It wasn't.
I've read a lot - and more. But I just can not find my mistake.
I get this Exception:
javax.faces.FacesException: javax.el.PropertyNotFoundException: //C:/01_java/ws_bsp/bsp/bsp-web/src/main/webapp/jsf/allgemein/login.xhtml #29,86 value="#{logInOutController.username}": Target Unreachable, identifier 'logInOutController' resolved to null
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:273)
at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:57)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1193)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
Truncated. see log file for complete stacktrace
Caused By: javax.el.PropertyNotFoundException: //C:/01_java/ws_bsp/bsp/bsp-web/src/main/webapp/jsf/allgemein/login.xhtml #29,86 value="#{logInOutController.username}": Target Unreachable, identifier 'logInOutController' resolved to null
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
at org.primefaces.util.ComponentUtils.getConverter(ComponentUtils.java:152)
at org.primefaces.renderkit.InputRenderer.getConvertedValue(InputRenderer.java:199)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1045)
at javax.faces.component.UIInput.validate(UIInput.java:975)
Truncated. see log file for complete stacktrace
Caused By: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'logInOutController' resolved to null
at com.sun.el.parser.AstValue.getTarget(AstValue.java:173)
at com.sun.el.parser.AstValue.getType(AstValue.java:85)
at com.sun.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:201)
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)
at org.primefaces.util.ComponentUtils.getConverter(ComponentUtils.java:152)
Truncated. see log file for complete stacktrace
Environment:
WLS 12.2.1.3.0
Java EE 7
ejb-project & web-project -> ear-project -> parent project
parent project pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xxx.yyy</groupId>
<artifactId>bsp</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>bsp</name>
<properties>
<application.name>bsp</application.name>
<application.ear.name>bsp-ear</application.ear.name>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modules>
<module>bsp-ear</module>
<module>bsp-web</module>
<module>bsp-ejb</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.3.7.Final</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.12</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>6.2</version>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>primefaces-extensions</artifactId>
<version>6.2.10</version>
</dependency>
<dependency>
<groupId>com.oracle.weblogic</groupId>
<artifactId>wls-api</artifactId>
<version>12.2.1-0-0</version>
</dependency>
</dependencies>
ear project pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>bsp</artifactId>
<groupId>xxx.yyy</groupId>
<version>1.0</version>
</parent>
<artifactId>bsp-ear</artifactId>
<packaging>ear</packaging>
<name>bsp-ear</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<version>6</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<modules>
<webModule>
<groupId>xxx.yyy</groupId>
<artifactId>bsp-web</artifactId>
<contextRoot>/bsp</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>xxx.yyy</groupId>
<artifactId>bsp-ejb</artifactId>
<version>1.0</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>xxx.yyy</groupId>
<artifactId>bsp-web</artifactId>
<version>1.0</version>
<type>war</type>
</dependency>
</dependencies>
ejb project pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>bsp</artifactId>
<groupId>xxx.yyy</groupId>
<version>1.0</version>
</parent>
<artifactId>bsp-ejb</artifactId>
<packaging>ejb</packaging>
<name>bsp-ejb</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
</plugins>
</build>
web project pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>bsp</artifactId>
<groupId>xxx.yyy</groupId>
<version>1.0</version>
</parent>
<artifactId>bsp-web</artifactId>
<packaging>war</packaging>
<name>bsp-web</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>xxx.yyy</groupId>
<artifactId>bsp-ejb</artifactId>
<version>1.0</version>
<type>ejb</type>
<scope>provided</scope>
</dependency>
</dependencies>
xhtml:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<f:view contentType="text/html">
<h:head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="author"
content="ABC" />
<meta http-equiv="Cache-Control"
content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="expires" content="0" />
<title><ui:insert name="title">#{app['name']}</ui:insert></title>
<link type="text/css" rel="stylesheet"
href="#{facesContext.externalContext.requestContextPath}/layout/css/custom.css" />
</h:head>
<h:body>
<p:growl id="messages" sticky="true" showSummary="true" showDetail="true"/>
<h:panelGrid id="headerTopPanel" styleClass="zColumnTopAlign">
<h:panelGrid id="headlinePanel" columns="3"
columnClasses="zHeaderLinks, zHeaderMitte, zHeaderRechts">
<logo>bsp</logo>
<h:panelGrid id="topMenuPanel">
<ui:insert name="topMenu" />
</h:panelGrid>
<h:panelGrid id="iconMenuPanel">
<ui:insert name="iconMenu" />
</h:panelGrid>
</h:panelGrid>
</h:panelGrid>
<h:panelGrid id="headerBottomPanel">
<h:panelGrid id="breadcrumbPanel" columns="2"
columnClasses="zLeft, zRight">
<h:panelGrid>
<ui:insert name="breadcrumb" />
</h:panelGrid>
<h:panelGrid>
<p:ajaxStatus styleClass="zAjaxStatus">
<f:facet name="start">
<p:commandLink styleClass="iconLoading" />
</f:facet>
<f:facet name="complete">
<h:outputText value="" />
</f:facet>
</p:ajaxStatus>
</h:panelGrid>
</h:panelGrid>
</h:panelGrid>
<p:separator id="menuSeparator" />
<h:panelGrid id="middlePanel" styleClass="zColumnTopAlign">
<!-- <h:panelGrid id="messagesPanel">
<p:messages id="messages" showIcon="false"/>
</h:panelGrid> -->
<h:panelGrid id="sideMenuContentPanel" columns="2"
columnClasses="z12percentBreit zLeft, z88percentBreit zLeft zOverflowAuto">
<h:panelGrid id="sideMenuPanel">
<ui:insert name="sideMenu" />
</h:panelGrid>
<h:panelGrid id="contentPanel">
<ui:insert name="content" />
</h:panelGrid>
</h:panelGrid>
</h:panelGrid>
</h:body>
</f:view>
</html>
Controller:
package xxx.yyy.controller;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import xxx.yyy.util.MessageHelper;
import xxx.yyy.util.PropertiesUtil;
#Named
#RequestScoped
public class LogInOutController {
#Inject
private PropertiesUtil propertiesUtil;
private String username;
private String password;
private String test = "test";
public String login() {
if (username.equals("bsp") && password.equals("bsp")) {
MessageHelper.showInfoMessage(propertiesUtil.getAppProperty("halloTest"), this);
}
return null;
}
public String logout() {
return null;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
}
If that is not enough or more is needed, please let me know.
I would be overjoyed if someone could help me.
Thanks in advance
I finally found the reason it didn't work.
I had to change the publishing mode of the WebLogic Server:
Right Click on Server -> Properties -> WebLogic -> Publishing -> Publish as an exploded archive

Fileupload does not work in Primefaces

I have some issues with the <p:fileUpload> in Primefaces. At first I tried the snippets in the Documentation of Fileupload starting on page 2018.
The first issue was that if I use the snippet, the upload function is not called:
public void upload() {
System.out.println("This is never shown");
if(file != null) {
System.out.println("This is never shown");
}
}
html:
<h:form enctype="multipart/form-data">
<p:fileUpload value="#{fileUploadView.file}" mode="simple" />
<p:commandButton value="Submit" action="#{fileUploadView.upload}" ajax="false"/>
</h:form>
I have tried many other snippets and solutions. Advanced mode, with fileUploadListener, deleted the enctype in h:form, ....
If I choose mode="simple" and combine it with ajax="true" the function FileUploadView.upload() is called, but the file is always NULL.
If I delete the enctype from the <h:form>, the function FileUploadView.upload() is called, but the file is always NULL.
I mention the issues above, because this should not work either, because I read all possible solutions on this forum. I also added all suggested dependencies and context-params and filter, but it does not work.
Here I will post my pom.xml, web.xml and the full .java code:
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>at.qe</groupId>
<artifactId>ASN_Application</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<name>ASN_Application</name>
<description>
</description>
<repositories>
<repository>
<id>prime-repo</id>
<name>Prime Repo</name>
<url>http://repository.primefaces.org</url>
</repository>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<properties>
<start-class>at.qe.sepm.asn_app.Main</start-class>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.10</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0-PFD2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.14</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.13</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>6.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.16</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>
<!-- special test dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>2.1.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- Enable jacoco analysis -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>once</forkMode>
<argLine>
${coverageAgent}
</argLine>
<useSystemClassLoader>true</useSystemClassLoader>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</version>
<configuration>
<propertyName>coverageAgent</propertyName>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<error-page>
<exception-type>org.springframework.security.access.AccessDeniedException</exception-type>
<location>/error/access_denied.xhtml</location>
</error-page>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>primefaces.FONT_AWESOME</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>commons</param-value>
</context-param>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<mime-mapping>
<extension>eot</extension>
<mime-type>application/vnd.ms-fontobject</mime-type>
</mime-mapping>
<mime-mapping>
<extension>otf</extension>
<mime-type>font/opentype</mime-type>
</mime-mapping>
<mime-mapping>
<extension>ttf</extension>
<mime-type>application/x-font-ttf</mime-type>
</mime-mapping>
<mime-mapping>
<extension>woff</extension>
<mime-type>application/x-font-woff</mime-type>
</mime-mapping>
<mime-mapping>
<extension>svg</extension>
<mime-type>image/svg+xml</mime-type>
</mime-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>login.xhtml</welcome-file>
</welcome-file-list>
</web-app>
FileUploadView.java
#Component
#Scope("view")
public class FileUploadView{
#Autowired
private PictureService pictureService;
#Autowired
private UserRepository userRepository;
#Autowired
private AuditLogRepository auditLogRepository;
private Picture picture;
private UploadedFile file;
public Picture getPicture(){
return picture;
}
public void setPicture(Picture picture){
this.picture = picture;
}
public UploadedFile getFile() {
return file;
}
public void setFile(UploadedFile file) {
this.file = file;
}
#PostConstruct
public void init(){
file= new DefaultUploadedFile();
}
public void upload() {
if(file != null) {
try{
System.out.println("This is never shown");
AuditLog log = new AuditLog(getAuthenticatedUser().getUsername(),"PICTURE UPLOADED: " + getAuthenticatedUser().getUsername() + " [" + getAuthenticatedUser().getUserRole() + "] ", new Date());
auditLogRepository.save(log);
System.out.println(file.getFileName());
picture = new Picture(file.getFileName(), userRepository.findFirstByUsername(auth.getName()), new Date(), file.getFileName());
pictureService.savePicture(picture);
FacesMessage message = new FacesMessage("Succesful", file.getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, message);
String filename = FilenameUtils.getName(file.getFileName());
InputStream input = file.getInputstream();
OutputStream output = new FileOutputStream(new File( filename));
try {
IOUtils.copy(input, output);
} finally {
IOUtils.closeQuietly(input);
IOUtils.closeQuietly(output);
}
}catch(Exception e)
{
}
}
}
I would appreciated if someone could help me finding the problem.
Thanks in advance
[EDIT]: I have tried to make a clean Spring project and tried all of the possibilities to make a <p:fileUpload>, but none of them work. But I looked on the traffic of my browser, and I found out something interesting:
. The POST statement appears immediately after I pressed the uploadbutton, the other GETs appear 1-2 seconds after.
The documentation says
Advanced File Upload
FileUploadListener is the way to access the uploaded files in this mode, when a file is uploaded
defined fileUploadListener is processed with a FileUploadEvent as the parameter.
Add the fileUploadListener with a FileUploadEvent parameter. Make the button AJAXical. Lose the enctype. Don't bother with fileUpload's value.

Struts JSP page does not display correctly, it shows the unparsed source code in browser

I use Tomcat 8 and Struts 1.3.10
when i execute my application
http://127.0.0.1:8080/appli/welcome.jsp
i have this in my browser
<%# taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<%# taglib uri="http://struts.apache.org/tags-html-el" prefix="html"
%> <%# taglib uri="http://struts.apache.org/tags-bean-el"
prefix="bean" %> <%# taglib uri="http://java.sun.com/jstl/core"
prefix="c" %> <%# taglib uri="http://struts.apache.org/tags-logic-el"
prefix="logic" %> "> ">
Message in the console:
2016-01-21 15:20:39 DEBUG ModuleUtils:171 - Get module name for path
/generic/authentification/Login.do 2016-01-21 15:20:39 DEBUG
ModuleUtils:196 - Module name found: default 2016-01-21 15:20:39 DEBUG
RequestProcessor:161 - Processing a 'GET' for path
'/generic/authentification/Login' 2016-01-21 15:20:39 DEBUG
TilesRequestProcessor:265 -
uri=/WEB-INF/jsp/generic/tiles/template_blank.jsp doInclude=false
2016-01-21 15:25:12 DEBUG ApplicationFilter:59 - Requested path :
'/accueil.jsp' - method : GET 2016-01-21 15:25:12 DEBUG
ApplicationFilter:63 - Acces refusé 2016-01-21 15:25:12 DEBUG
ModuleUtils:171 - Get module name for path
/generic/authentification/Login.do 2016-01-21 15:25:12 DEBUG
ModuleUtils:196 - Module name found: default 2016-01-21 15:25:12 DEBUG
RequestProcessor:161 - Processing a 'GET' for path
'/generic/authentification/Login' 2016-01-21 15:25:12 DEBUG
TilesRequestProcessor:265 -
uri=/WEB-INF/jsp/generic/tiles/template_blank.jsp doInclude=false
what's wrong ? I forget to configure
some things ?
My Pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.project</groupId>
<artifactId>appli</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>appli</name>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<!-- Applicatif -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.0.7.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-core</artifactId>
<version>1.3.10</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-extras</artifactId>
<version>1.3.10</version>
</dependency>
<!-- JSP TLD -->
<dependency>
<groupId>net.fckeditor</groupId>
<artifactId>java-core</artifactId>
<version>2.6</version>
</dependency>
<!-- <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId>
<version>1.1.2</version> </dependency> -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-taglib</artifactId>
<version>1.3.10</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-el</artifactId>
<version>1.3.10</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-tiles</artifactId>
<version>1.3.10</version>
</dependency>
<!-- Birt -->
<dependency>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.eclipse.birt.runtime</artifactId>
<version>4.3.0</version>
<exclusions>
<exclusion>
<artifactId>org.apache.poi</artifactId>
<groupId>org.eclipse.birt.runtime</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<!-- Divers -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>com.novell.ldap</groupId>
<artifactId>jldap</artifactId>
<version>2009-10-07</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
<version>1.5.5</version>
</dependency>
</dependencies>
<build>
<finalName>apex</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<archive>
<manifestEntries>
<Specification-Title>J2EE Servlet</Specification-Title>
<Specification-Version>2.5</Specification-Version>
<Specification-Vendor>Sun Microsystems</Specification-Vendor>
<Implementation-Title>${pom.name}</Implementation-Title>
<Implementation-Version>${pom.version}</Implementation-Version>
<Implementation-Vendor>${pom.organization.name}</Implementation-Vendor>
<Built-By>me</Built-By>
<Implementation-URL>${pom.url}</Implementation-URL>
</manifestEntries>
</archive>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
welcome.jsp:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Example</title>
</head>
<body>
<html:form action="/login" focus="userName">
Username : <html:text property="userName" />
<br>
Password : <html:password property="password" />
<br>
<html:submit value="login" />
</html:form>
</body>
</html>
web.xml
when i comment the two line all it work but when i uncomment this line i have the pb
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>Struts Blank Application</display-name>
<!-- Standard Action Servlet Configuration -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<!-- <init-param> <param-name>chainConfig</param-name> <param-value>org/apache/struts/tiles/chain-config.xml</param-value>
</init-param> -->
<load-on-startup>2</load-on-startup>
</servlet>
<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- <servlet-mapping> -->
<!-- <servlet-name>jsp</servlet-name> -->
<!-- <url-pattern>/javascript/generic/messages.js</url-pattern> -->
<!-- </servlet-mapping> -->
<!-- <servlet-mapping> -->
<!-- <servlet-name>jsp</servlet-name> -->
<!-- <url-pattern>*.css</url-pattern> -->
<!-- </servlet-mapping> -->
<!-- The Usual Welcome File List -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
If you have unparsed code in jsp page means that
JSP engine didn't run at all
You have overridden web configuration in web.xml. because you didn't post it with the question I can't tell you where it's wrong. May be you have incorrectly mapped an action servlet to /*. This is just standard configuration
<!-- Standard Action Servlet Configuration -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

Swagger spitting out xml response instead of json

I'm a week old in spring. I'm developing a pure RESTful API service using Spring + maven + Jackson. While exploring some best practices, I came across this, so I decided I'll be using swagger with spring mvc (and swaggerUI) for documentation. I went through this and this tutorial for doing what I wanted. Everything was going fine and dandy until I realized after hitting /api-docs I got XML response, as opposed to JSON response in tutorials and every-other-where. This won't work fine when I add SwaggerUI. Later I found out here that swaggerUI expects json. I could always go back and use swagger without server integration (https://github.com/wordnik/swagger-core/wiki/Adding-Swagger-to-your-API), but that won't really satisfy my needs.
Here are the contents of pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.darshandzend</groupId>
<artifactId>swjs</artifactId>
<name>swjs</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
<java-version>1.6</java-version>
<org.springframework-version>3.1.1.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.6.6</org.slf4j-version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>
<!-- #Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-core</artifactId>
<version>1.1-SNAPSHOT.121130</version>
</dependency>
<dependency>
<groupId>com.mangofactory</groupId>
<artifactId>swagger-springmvc</artifactId>
<version>0.6.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.test.int1.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
servlet context:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing
infrastructure -->
<!-- Enables the Spring MVC #Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving
up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by #Controllers to .jsp resources
in the /WEB-INF/views directory -->
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="com.darshandzend.swjs" />
<beans:bean class="com.mangofactory.swagger.configuration.DocumentationConfig" />
<context:property-placeholder location="classpath:/swagger.properties" />
swagger.properties
documentation.services.version=1.0
documentation.services.basePath=http://localhost:8080/swjs/
I tried GET /api-docs/ in chrome dev http tool with "Accept" header set to "application/json", which worked. Does this mean I manually have to set request headers somewhre? I'm adding web.xml just in case.
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I reckon swagger won't require any special annotations so my java codebase remains the same.
Is this question too long? Pardon me, for I'm new to SO. Please edit and suggest.
Controller class:
#Api(value = "contacts", description = "contacts") // Swagger annotation
#Controller
#RequestMapping("/home")
public class HomeController {
#ResponseBody
#RequestMapping(method=RequestMethod.GET)
public Response select() {
return new Response("success", "", "this is the humble abode of everything");
}
#ResponseBody
#RequestMapping(value="/{id}",method=RequestMethod.GET)
public Response get(#PathVariable String id) {
return new Response("Success", "", id);
}
}
Swagger-ui does not set an Accept header with its AJAX requests. Unfortunately swagger-springmvc returns XML if no accept header or no path extension (.json) is given.
You can manually add a JSON accept header to every request swagger-ui executes. Simply add the following JavaScript line to your swagger-ui index.html file:
window.authorizations.add("Accept",
new ApiKeyAuthorization("Accept", "application/json", "header"));
This is my modified index.html file:
<!DOCTYPE html>
<html>
<head>
<title>Swagger UI</title>
<link href='//fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
<link href='css/highlight.default.css' media='screen' rel='stylesheet' type='text/css'/>
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
<script type="text/javascript" src="lib/shred.bundle.js"></script>
<script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script>
<script src='lib/jquery.slideto.min.js' type='text/javascript'></script>
<script src='lib/jquery.wiggle.min.js' type='text/javascript'></script>
<script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
<script src='lib/handlebars-1.0.0.js' type='text/javascript'></script>
<script src='lib/underscore-min.js' type='text/javascript'></script>
<script src='lib/backbone-min.js' type='text/javascript'></script>
<script src='lib/swagger.js' type='text/javascript'></script>
<script src='swagger-ui.js' type='text/javascript'></script>
<script src='lib/highlight.7.3.pack.js' type='text/javascript'></script>
<script type="text/javascript">
$(function () {
window.swaggerUi = new SwaggerUi({
url: "http://localhost:8080/api-docs",
dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
onComplete: function(swaggerApi, swaggerUi){
if(console) {
console.log("Loaded SwaggerUI")
}
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
},
onFailure: function(data) {
if(console) {
console.log("Unable to Load SwaggerUI");
console.log(data);
}
},
docExpansion: "none"
});
window.authorizations.add("Accept", new ApiKeyAuthorization("Accept", "application/json", "header"));
$('#input_apiKey').change(function() {
var key = $('#input_apiKey')[0].value;
console.log("key: " + key);
if(key && key.trim() != "") {
console.log("added key " + key);
window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "query"));
}
})
window.swaggerUi.load();
});
</script>
</head>
<body>
<div id='header'>
<div class="swagger-ui-wrap">
<a id="logo" href="http://swagger.wordnik.com">swagger</a>
<form id='api_selector'>
<div class='input icon-btn'>
<img id="show-pet-store-icon" src="images/pet_store_api.png" title="Show Swagger Petstore Example Apis">
</div>
<div class='input icon-btn'>
<img id="show-wordnik-dev-icon" src="images/wordnik_api.png" title="Show Wordnik Developer Apis">
</div>
<div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
<div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/></div>
<div class='input'><a id="explore" href="#">Explore</a></div>
</form>
</div>
</div>
<div id="message-bar" class="swagger-ui-wrap">
</div>
<div id="swagger-ui-container" class="swagger-ui-wrap">
</div>
</body>
</html>

Spring MVC and JSP - can not pass data from controller to jsp

I have a GWT Application with Spring MVC support. I've defined a spring controller:
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
#Controller
public class IndexController {
#RequestMapping("/")
public ModelAndView index(HttpServletRequest request) {
ModelAndView result = new ModelAndView("index");
result.addObject("message", "hello, world!");
return result;
}
}
and this controller returns simple jsp-based view:
<%#page pageEncoding="UTF-8"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%# taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Они с нами</title>
<link href="<%=getServletContext().getContextPath()%>/style/reset.css" rel="stylesheet" type="text/css"></link>
<link href="<%=getServletContext().getContextPath()%>/style/index.css" rel="stylesheet" type="text/css"></link>
<link href="<%=getServletContext().getContextPath()%>/style/common.css" rel="stylesheet" type="text/css"></link>
<script type="text/javascript" language="javascript" src="<%=getServletContext().getContextPath()%>/stub/stub.nocache.js"></script>
</head>
<body>
<p style="display:none">${message}</p>
</body>
</html>
URL mapping and redirecting to the view works OK, but,
<p style="display:none">${message}</p>
does not works - it just prints ${message}
Here is my web.xml:
<web-app>
<!-- Reads request input using UTF-8 encoding -->
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>springMvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMvc</servlet-name>
<url-pattern>/index/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index/</welcome-file>
</welcome-file-list>
</web-app>
and my springMvc-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<context:component-scan base-package="com.onisnami.site.server.controllers"/>
</beans>
Also pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<!-- POM file generated with GWT webAppCreator -->
<modelVersion>4.0.0</modelVersion>
<groupId>com.onisnami</groupId>
<artifactId>onisnami-site</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>GWT Maven Archetype</name>
<properties>
<!-- Convenience property to set the GWT version -->
<gwtVersion>2.1.1</gwtVersion>
<!-- GWT needs at least java 1.5 -->
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<org.springframework.version>3.0.5.RELEASE</org.springframework.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwtVersion}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.gwt.inject</groupId>
<artifactId>gin</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>net.customware.gwt.dispatch</groupId>
<artifactId>gwt-dispatch</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-servlet</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
<build>
<!-- Generate compiled stuff in the folder used for developing mode -->
<outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
<plugins>
<!-- GWT Maven Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.1.0-1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<!-- <goal>test</goal>
<goal>i18n</goal>
<goal>generateAsync</goal> -->
</goals>
</execution>
</executions>
<!-- Plugin configuration. There are many available options, see gwt-maven-plugin
documentation at codehaus.org -->
<configuration>
<runTarget>stub.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
</configuration>
</plugin>
<!-- Copy static web files before executing gwt:run -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
<configuration>
<webappDirectory>${webappDirectory}</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
A spent all day in the searching of solution, but it still does not work. Help me please.
Thank you
You are correct, since you are defining expressions
${Anything between this is expression}
You need to include
<%#page isELIgnored="false" %>
isELIgnored is false, i.e Expressions are taken into account.
The solution is found:
it is needed to add following lines:
<%#page contentType="text/html;charset=UTF-8" language="java" %>
<%#page isELIgnored="false" %>
At the begin of the JSP file

Resources