rich:GateIn portlet 中的 fileUpload
环境:RichFaces 3.3.3 Final; Facelets 1.1.15; JBoss portletbridge 2.1.0 最终版; GateIn Portal 3.1.0 与 JBoss AS 5.1 和内置的 Mojarra JSF 1.2 捆绑在一起。
一些代码片段: filepage.xhtml:
<a4j:form id="fileForm">
<rich:fileUpload fileUploadListener="#{testBean.fileListener}"
acceptedTypes="txt" maxFilesQuantity="1" />
<!-- etc. -->
</a4j:form>
TestBean.java:
public void fileListener(UploadEvent e) throws IOException {
System.out.println("Entering the fileListener Method");
UploadItem item = e.getUploadItem();
File file = item.getFile();
// etc...
}
部署为独立 Web 应用程序时的结果符合预期,组件显示,用户单击“添加”,浏览然后选择一个文件,文件被添加到列表中,用户单击上传按钮,然后控制台上显示“输入 fileListener 方法”行(以及发生的其他事情)。
GateIn 上的结果:除 sysout 和侦听器中的其他代码之外的所有内容。看来这个方法没有被调用。
我已经花了几天时间阅读 JBoss 社区论坛和一些 JIRA,看来我的问题并不新鲜。我尝试了我找到的每一个建议,但没有一个对我有用。此外,这些帖子都不是 2010 年 1 月更新的,从那时起,我的应用程序的所有组成部分都有了新版本。
非常感谢您的帮助或最新详细信息的提示。
Environment: RichFaces 3.3.3 Final; Facelets 1.1.15; JBoss portletbridge 2.1.0 Final; GateIn Portal 3.1.0 as bundled with JBoss AS 5.1 and the Mojarra JSF 1.2 which is built in.
Some code snippets:
filepage.xhtml:
<a4j:form id="fileForm">
<rich:fileUpload fileUploadListener="#{testBean.fileListener}"
acceptedTypes="txt" maxFilesQuantity="1" />
<!-- etc. -->
</a4j:form>
TestBean.java:
public void fileListener(UploadEvent e) throws IOException {
System.out.println("Entering the fileListener Method");
UploadItem item = e.getUploadItem();
File file = item.getFile();
// etc...
}
Result when deployed as a stand-alone web app is as expected, the component displays, user clicks add, browses then selected a file, file is added to the list, user clicks upload button, and the line "Entering the fileListener Method" displays on the console (along with other things happening).
Result on GateIn: All of the above EXCEPT the sysout and other code in the listener. It appears that this method is not getting called.
I have already spent a few days reading through JBoss community forums and a few JIRAs, and it seems my problem is not new. I tried each of the suggestions I found, but none worked for me. Also, none of these posts were more recent than Jan 2010, and all of the constituent parts of my app have had new versions since then.
Your assistance, or a pointer to up-to-date and detailed information, is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不认为这是我自己问题的答案,但这对于评论来说太大了,我不想通过将其添加为编辑来影响答案。不管怎样,根据同事的建议,我有一个解决方法。
正如我在问题中提到的,文件上传在独立的 Web 应用程序中完美运行,所以为什么不让 portlet 仅指向该 Web 应用程序,而不是成为该 Web 应用程序。
在 portlet.xml 中,将
从 javax.portlet.faces.GenericFacesPortlet 更改为您创建的 java portlet,例如 mypackage.DispatchPortlet。同时删除带有 defaultViewId 的
。DispatchPortlet 与其他所有内容都位于同一个项目中,并且只比入口 HelloWorld portlet 复杂一步。只需重写 doView 并添加以下四行:
HTML_CONTENT 是一个静态字符串变量,看起来有点像:
这就是它所需要的全部内容。人们几乎想知道为什么我们要费心建立一个 portlet 桥。不仅一切正常,而且看起来也好一些,因为 GateIn 对 CSS 所做的一些时髦的事情并没有发生。
然而,我认为这是一个 ghetto 解决方案,并且我确实在寻找正确的方法来使其成为 100% portlet,并且具有功能性的文件上传功能。
I do not consider this an answer to my own question, but this is too large for a comment and I do not want to influence answers by adding this as an edit. Anyway, at a suggestion from a colleague, I have a work-around of sorts.
As I mention in the question, the file upload works perfectly within a stand-alone web-app, so why not make the portlet merely POINT TO that web-app, rather than BE that web-app.
In portlet.xml, change the
<portlet-class>
from javax.portlet.faces.GenericFacesPortlet to a java portlet you create, say mypackage.DispatchPortlet. Also remove the<init-param>
with defaultViewId's.The DispatchPortlet is in the same project as the everything else, and is barely a step more complex than the entry HelloWorld portlet. Just override doView and add these four little lines:
HTML_CONTENT is a static String variable that looks a little like:
That's litterally all it takes. One almost wonders why we bother having a portlet bridge. Not only does everything work, but it also looks a little better because some of the funky stuff GateIn does to CSS doesn't happen.
However, I consider this a ghetto solution and am really looking for the right way to make this a 100% portlet, with functioning file upload.
我在 Red Hat EPP 的文档中找到了不支持文件上传的信息。也许当下一个版本准备就绪时(支持 JSF 2、Richfaces 4 和 Bridge 3),那么它就会实现,但就目前而言,解决方法是唯一的选择。
I located in the documentation for Red Hat EPP that file upload is not supported. Perhaps when the next version is ready (to support JSF 2, Richfaces 4, and Bridge 3) then it will be, but for now, the work-around is the only choice.