t:inputFileUpload 从mapped(pretty faces) .xhtml 页面调用时不起作用
我正在使用 Tomahawk 库进行文件上传。 但是,当我单击 h:commandButton 提交表单时,永远不会调用支持 bean 的方法。
下面是应该完成这项工作的代码序列,它是 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 映射,如下所示:
<url-mapping id="user_profile">
<pattern value="/user/#{id}"></pattern>
<view-id value="/user_profile.jsf"></view-id>
</url-mapping>
但是,当我直接访问页面时,通过避免 Pretty -配置映射, 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>
...
I'm using Tomahawk library for the file upload.
However, the backing bean's method is never called when I click on h:commandButton to submit the form.
Bellow is the code sequence that should do the job, and it is a part of user_profile.xhtml page(which is stored in the root of WebContent folder; the application is deployed on 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>
The link that provides access to the page is http://localhost:8080/user/20, because there is url-mapping set in pretty-config.xml file, which looks like:
<url-mapping id="user_profile">
<pattern value="/user/#{id}"></pattern>
<view-id value="/user_profile.jsf"></view-id>
</url-mapping>
However, when I access the page directly, by avoiding pretty-config mapping, http://localhost:8080/user_profile.jsf, upload action works fine!
So, I suppose there is some conflict with pretty faces or I overlooked something.
Thanks in advance!
The beginning of 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>
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Tomahawk 过滤器未正确注册(未定义调度程序)。应该这样做:
这解决了问题。
The Tomahawk filter was not registered properly (there were no dispatcher(s) defined). This is how it should be done:
This solved the problem.