[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/ui ...
Christian Bauer
christian at hibernate.org
Sun Mar 18 15:01:15 EDT 2007
User: cbauer
Date: 07/03/18 15:01:15
Modified: examples/wiki/src/main/org/jboss/seam/wiki/core/ui
FileServlet.java
Log:
Fixed file download servlet and attachment display
Revision Changes Path
1.4 +14 -3 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/FileServlet.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: FileServlet.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/FileServlet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- FileServlet.java 18 Mar 2007 15:44:37 -0000 1.3
+++ FileServlet.java 18 Mar 2007 19:01:15 -0000 1.4
@@ -1,6 +1,8 @@
package org.jboss.seam.wiki.core.ui;
import org.jboss.seam.wiki.core.model.File;
+import org.jboss.seam.util.Transactions;
+import org.jboss.seam.*;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
@@ -8,6 +10,9 @@
import javax.servlet.http.HttpServlet;
import javax.servlet.ServletException;
import javax.swing.*;
+import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
+import javax.transaction.UserTransaction;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
@@ -55,7 +60,6 @@
File file = null;
// TODO: Seam should use its transaction interceptor for java beans: http://jira.jboss.com/jira/browse/JBSEAM-957
- /* Disabled because I can't get the restrictedEntityManager here, need to implement workaround
UserTransaction userTx = null;
boolean startedTx = false;
try {
@@ -68,7 +72,15 @@
EntityManager em = ((EntityManager)org.jboss.seam.Component.getInstance("restrictedEntityManager"));
em.joinTransaction();
- file = (!"".equals(id)) ? em.find(File.class, Long.parseLong(id)) : null;
+ if (!"".equals(id)) {
+ try {
+ file = (File)em.createQuery("select f from File f where f.id = :fid")
+ .setParameter("fid", Long.parseLong(id))
+ .getSingleResult();
+ } catch (NoResultException ex) {
+ // ignore... we want null
+ }
+ }
if (startedTx) userTx.commit();
} catch (Exception ex) {
@@ -79,7 +91,6 @@
}
throw new RuntimeException(ex);
}
- */
String contentType = null;
byte[] data = null;
More information about the jboss-cvs-commits
mailing list