0

我正在使用 Tomahawk 库进行文件上传。但是,当我单击h:commandButton提交表单时,永远不会调用支持 bean 的方法。

Bellow 是应该完成这项工作的代码序列,它是 user_profile.xhtml 页面的一部分(存储在 WebContent 文件夹的根目录中;应用程序部署在 JBoss 6.1 上):

<p:dialog widgetVar="avatar" hideEffect="fade" width="300" height="300"
    header="Avatar upload">
    <h:form enctype="multipart/form-data">
        <t:inputFileUpload value="#{uploadBean.uploadedFile}" id="upload" />
        <h:commandButton value="Upload" action="#{uploadBean.submit}" />
    </h:form>
</p:dialog>

提供对页面访问的链接是http://localhost:8080/user/20,因为在 pretty-config.xml 文件中设置了 url-mapping,如下所示:

<url-mapping id="user_profile">
    <pattern value="/user/#{id}"></pattern>
    <view-id value="/user_profile.jsf"></view-id>
</url-mapping>

但是,当我直接访问该页面时,通过避免漂亮的配置映射http://localhost:8080/user_profile.jsf,上传操作可以正常工作!所以,我想与漂亮的面孔有些冲突,或者我忽略了一些东西。

提前致谢!

web.xml的开头:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="YAS" version="3.0">
  <display-name>YouAndShoe</display-name>

  <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
 </context-param>

  <filter>
    <filter-name>MyFacesExtensionsFilter</filter-name>
    <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>MyFacesExtensionsFilter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
  </filter-mapping>

  <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>
...
4

1 回答 1

2

Tomahawk 过滤器未正确注册(未定义调度程序)。应该这样做:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="YAS" version="3.0">
  <display-name>YouAndShoe</display-name>

  <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
 </context-param>



  <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>MyFacesExtensionsFilter</filter-name>
  <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>MyFacesExtensionsFilter</filter-name>
  <servlet-name>Faces Servlet</servlet-name>
  <dispatcher>FORWARD</dispatcher>
  <dispatcher>REQUEST</dispatcher>
  <dispatcher>ERROR</dispatcher>
</filter-mapping>
<filter-mapping>
  <filter-name>MyFacesExtensionsFilter</filter-name>
  <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
  <dispatcher>FORWARD</dispatcher>
  <dispatcher>REQUEST</dispatcher>
  <dispatcher>ERROR</dispatcher>
</filter-mapping> 
...

这解决了问题。

于 2011-12-23T14:30:50.283 回答