我在我的项目PrimeFaces 5.3中使用PrettyFaces 3.3.3。我得到的问题是上传文件(ajax上传)
<div>
这是我的prettyfaces配置文件(来自manage bean的动态set view-id)
<p:fileUpload
fileUploadListener="#{userProductsView.handlePrimaryImageUpload}"
value="#{userProductsView.primaryImageTemp}"
process="@this"
auto="true"
mode="advanced"
label=" " />
并管理bean:
<url-mapping id="global_login">
<pattern value="/logowanie" />
<view-id value="#{routesService.getViewPath}" />
</url-mapping>
我调查了那个。当我不使用bean的动态view-id(通过routesService)值时,例如:
@RequestScoped // javax.enterprise.context.RequestScoped
@Named("routesService") // javax.inject.Named
public class RoutesService {
private Map<String, String> resources;
public String getView(String pattern) {
return resources.get(pattern);
}
public String getViewPath() {
String path = "/";
UrlMapping currentMapping = PrettyContext.getCurrentInstance().getCurrentMapping();
if (currentMapping != null) {
String pattern = currentMapping.getPattern();
if (pattern != null) {
String[] splited = pattern.split("/");
if (splited.length > 1) {
path = "/" + splited[1];
}
}
}
return getView(path);
}
}
上传工作正常。我试图解决问题,但我没有想法我能做什么。任何人都可以帮助解决这个问题,我会感激任何帮助。
下面我在pom.xml和web.xml中加入了一些和平的web.xml:
<url-mapping id="global_login">
<pattern value="/logowanie" />
<view-id value="/faces/logowanie.xhtml" />
</url-mapping>
和pom.xml:
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>commons</param-value>
</context-param>
<!-- SERVLET -->
<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>*.xhtml</url-pattern>
</servlet-mapping>
<!-- FILTERS -->
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<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>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
根据BalusC评论:
我按以下顺序设置过滤器,两个过滤器都有模式/ *:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
在配置上传不起作用。 (之前它在PrettyFaces重写的URL上工作,但只有在映射到view-id时才在那个url上硬编码而不是从托管bean注入)。我需要从托管bean中注入view-id url,所以就是这个问题。似乎当PrettyFaces引擎从托管bean注入路径时发生问题