rich:GateIn portlet 中的 fileUpload

发布于 2024-11-09 11:51:11 字数 1005 浏览 7 评论 0原文

环境: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

邮友 2024-11-16 11:51:11

我不认为这是我自己问题的答案,但这对于评论来说太大了,我不想通过将其添加为编辑来影响答案。不管怎样,根据同事的建议,我有一个解决方法。

正如我在问题中提到的,文件上传在独立的 Web 应用程序中完美运行,所以为什么不让 portlet 仅指向该 Web 应用程序,而不是成为该 Web 应用程序。

在 portlet.xml 中,将 从 javax.portlet.faces.GenericFacesPortlet 更改为您创建的 java portlet,例如 mypackage.DispatchPortlet。同时删除带有 defaultViewId 的

DispatchPortlet 与其他所有内容都位于同一个项目中,并且只比入口 HelloWorld portlet 复杂一步。只需重写 doView 并添加以下四行:

 response.setContentType("text/html");
 PrintWriter out = response.getWriter();
 out.println(HTML_CONTENT);
 out.close();

HTML_CONTENT 是一个静态字符串变量,看起来有点像:

 <iframe src="url to your app" height="400" width="600">no iframes</iframe>

这就是它所需要的全部内容。人们几乎想知道为什么我们要费心建立一个 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:

 response.setContentType("text/html");
 PrintWriter out = response.getWriter();
 out.println(HTML_CONTENT);
 out.close();

HTML_CONTENT is a static String variable that looks a little like:

 <iframe src="url to your app" height="400" width="600">no iframes</iframe>

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.

苄①跕圉湢 2024-11-16 11:51:11

我在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文