Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
JSP - A mailing list about Java Server Pages specification and reference
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Servlet : Session invalidate
Oracle Connection Pooling in 3 2 2
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Running a Simple JMS Example
Tomcat and webapplication specific java library path
Mapping in workers2 properties
org apache jasper JasperException
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action
   MESSAGE
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
Value attribute of <html:checkbox
url string for connecting jboss to oracle
javax servlet ServletException: BeanUtils populate
5 0 18: Windows XP Pro vs Windows 2000
HTTP Status 404 The requested resource is not available
 
- Question concerning remoting

- Question concerning remoting

2007-08-13       - By campi

 Back
Hi,
I have a little problem that i cannot resolve, and I wanted to known your point
of vue concerning my problem.
I'am using :
- EJB3
- SEAM 1.2.1-GA
- JPBM 3.1.4
- JRules 3.0.8
- ....

My problem is in a part of the application I need to generate forms using xml
and xsl transformation. I have worked a lot on this point and everything is
working fine except the upload of files. I'm explaining the problem.

I'am using :


 |   @(protected) (value="#{facesContext.externalContext}")
 |   private ExternalContext extCtx;  
 |

With this I can get all the data submitted, and with JAXB (classes generated
from the xsd of the xml file) I stock the new xml with all the data into an
eXist Database (xml database).
My problem is concerning the part where I need to download a file that where
submitted to consult it. Due to the fact that I could map use jsf tag, I wanted
to use seam remoting to access a method use to download, but the problem is
that I don't have any access to the FaceContext when the javascript call is
made...

I post my test code example :

The JSF Page :

 |     <div class="main-part" id="main-part">
 |
 |       <script type="text/javascript" src="../seam/resource/remoting/resource
/remote.js"></script>
 |       <script type="text/javascript" src="../seam/resource/remoting/interface
.js?fileAction"></script>
 |      
 |       <script type="text/javascript">
 |       //<![CDATA[
 |      
 |       Seam.Remoting.setDebug(true);
 |      
 |       function download(fileName) {    
 |        Seam.Component.getInstance("fileAction").downloadFromRemoteJavascript
(fileName , downloadCallback);
 |       }
 |      
 |       function downloadCallback(result) {
 |        alert(result);
 |       }
 |      
 |       // ]]>
 |      </script>
 |
 |       <h:form id="form1" name="form1" enctype="multipart/form-data">
 |
 |         <f:subview rendered="#{testAction.fileName!=null}">
 |           <a href="#" onclick="javascript:download('#{testAction.fileName}');"
>Download #{testAction.fileName}</a><br/>
 |         </f:subview>
 |
 |         File : <input type="file" id="idFileInput" name="nameFileInput" title=
"titleFileInput" /><br />
 |
 |         <div class="breaker" />  
 |         <h:commandButton action="#{testAction.submit}" value="Submit" />        
 |
 |
 |       </h:form>
 |
 |     </div>
 |

The coordination Action Bean that is called when I sumit the form:

 | @(protected)("testAction")
 | @(protected)
 | public class TestActionBean implements TestAction {
 |
 |   @(protected)
 |   private Log log;
 |
 |   @(protected) (value="#{facesContext.externalContext}")
 |   private ExternalContext extCtx;  
 |  
 |   @(protected)(create=true)
 |   private Processor processor;
 |
 |   @(protected)(create=true)
 |   private FileManager fileManagerLocal;
 |  
 |   private String fileName;
 |  
 |   @(protected)
 |   @(protected)(join=true)
 |   public void begin() {
 |     log.info("Instanciation de la conversation");
 |   }
 |  
 |   /**
 |   * @(protected) ...#submit()
 |   */
 |   public void submit() {
 |     log.info("Submit");    
 |    
 |     try {
 |      
 |       //on convertis la request en multipart
 |       MultipartRequest multipartRequest = (MultipartRequest)extCtx.getRequest(
);
 |      
 |       //dans le cas o?? on aurait d??j?? upload?? un fichier, un supprime l
'ancien fichier pour que le nouveau le remplace
 |       if(this.fileName!=null){
 |         this.fileManagerLocal.deleteFile(this.fileName);
 |       }
 |      
 |       //on cr??e un objet de type Fichier avec les informations r??cup??r??
depuis la request
 |       Fichier fichier = new Fichier();
 |       fichier.setFileContentType(multipartRequest.getFileContentType(
"nameFileInput"));
 |       fichier.setFileName(multipartRequest.getFileName("nameFileInput"));
 |       fichier.setFileSize(multipartRequest.getFileSize("nameFileInput"));
 |       fichier.setFileData(multipartRequest.getFileBytes("nameFileInput"));
 |      
 |      
 |       //on sauvegarde sur le disque le fichier et on conserve le nom unique de
ce fichier
 |      
 |       this.fileName = FileTools.getFileNameFromUrl(this.fileManagerLocal
.saveFile(fichier),"/");
 |      
 |     } catch (IOException e) {
 |       log.error("Error : "+e);
 |       e.printStackTrace();
 |     } catch (InterruptedException e) {
 |       log.error("Error : "+e);
 |     }
 |    
 |   }
 |  
 |   ...
 |

The coordination Action Bean called into the javascript :

 | @(protected)("fileAction")
 | @(protected)
 | public class FileActionBean implements FileAction
 | {
 |    // d??claration du logger
 |    @(protected)
 |    private Log log;
 |  
 |    //Injections des managers situ??s dans les diff??rentes couches services
 |    @(protected)(create = true)
 |    private FileManager fileManagerLocal;
 |    
 |    /**
 |     * @(protected) ...#downloadFromRemoteJavascript
 |     */
 |    public boolean downloadFromRemoteJavascript(String fileName){
 |    
 |     boolean result = false;
 |    
 |     try {
 |
 |       //R??cup??ration de l'object Fichier associ?? au r??glement choisi
 |       log.info("Recherche du fichier en cours...");
 |       Fichier fichier = fileManagerLocal.searchFile(FileTools
.getFileNameFromUrl(fileName, "/"));
 |
 |       if(fichier != null){
 |         //this.popupFaceContextFileDownload(fichier);
 |         result = true;
 |       }
 |       else {
 |         FacesMessages.instance().addFromResourceBundle("file_not_found
_exception");
 |       }
 |     }
 |     catch (IOException e) {
 |       log.error("Erreur lors de la tentative de r??cup??ration du fichier
nomm??e "+fileName+" : "+e.getMessage());
 |     }
 |
 |     return result;
 |   }
 |
 |    /**
 |     * M??thode permettant de d??clencher le popup de t??l??chargement du
fichier qui a ??t?? demand??
 |     * @(protected) Fichier fichier
 |     */  
 |    private void popupFaceContextFileDownload (Fichier fichier) throws
IOException {
 |     FacesContext facesContext = FacesContext.getCurrentInstance();
 |
 |     HttpServletResponse response = (HttpServletResponse)facesContext
.getExternalContext().getResponse();
 |    
 |     response.flushBuffer();
 |  
 |     response.setHeader("Content-Disposition", "attachment; filename=\"" +
fichier.getFileName() + "\"");
 |     response.setBufferSize((int)fichier.getFileSize());
 |     response.setContentLength((int)fichier.getFileSize());
 |     response.setContentType(fichier.getFileContentType());
 |  
 |     ServletOutputStream servletOutputStream = response.getOutputStream();
 |     servletOutputStream.write(fichier.getFileData());
 |  
 |     servletOutputStream.flush();
 |     servletOutputStream.close();
 |     response.flushBuffer();
 |  
 |     facesContext.responseComplete();    
 |    }
 | }
 |

The service manager bean used into the two differents action bean of the
coordination layer :


 | @(protected)("fileManagerLocal")
 | @(protected)
 | public class FileManagerBeanLocal implements FileManager
 | {
 |
 |    private static final String FILE_PROPERTIES = "file.properties";
 |    private Properties properties = new Properties();
 |
 |    @(protected)
 |    Log log;
 |
 |    ....
 |
 |    /**
 |     * @(protected) IOException
 |     * @(protected) InterruptedException
 |     * @(protected) ...FileManager#saveFile(java.io.File)
 |     */
 |    public String saveFile(Fichier fichier) throws IOException,
InterruptedException
 |    {
 |
 |       // D??claration :
 |       String path;
 |       StringBuffer absolutePath;
 |       FileOutputStream fileOutputStream;
 |
 |       // Traitement :
 |       path = properties.getProperty("savePath");
 |       absolutePath = new StringBuffer();
 |
 |       /* Cr??er le chemin de sauvegarde */
 |       absolutePath.append(path).append("/").append(DateTools
.getFormattedDateNow()).append("-").append(fichier.getFileName());
 |       /* Ecriture du fichier */
 |       fileOutputStream = new FileOutputStream(absolutePath.toString());
 |       fileOutputStream.write(fichier.getFileData());
 |       fileOutputStream.flush();
 |       fileOutputStream.close();
 |
 |       return absolutePath.toString();
 |    }
 |
 |    /**
 |     * @(protected) IOException
 |     * @(protected) ...#searchFile(java.lang.String)
 |     */
 |    public Fichier searchFile(String fileName) throws IOException
 |    {
 |       String path = properties.getProperty("savePath") + "/";
 |       File searchedFile = new File(path + fileName);
 |       if (searchedFile.exists())
 |       {
 |          Fichier fichier = new Fichier();
 |          fichier.setFileData(this.readFile(searchedFile));
 |          fichier.setFileName(searchedFile.getName());
 |          fichier.setFileContentType(new MimetypesFileTypeMap()
.getContentType(searchedFile));
 |          fichier.setFileSize(searchedFile.length());
 |          return fichier;
 |       }
 |       else
 |          return null;
 |    }
 |
 |    ...
 | }
 |

My is that i calling the method downloadFromRemoteJavascript form the
fileAction Class when we arrive to the line commented that is calling the
private methode popupFaceContextFileDownload :


 | FacesContext facesContext = FacesContext.getCurrentInstance();
 |

The current instance is null so i cannot popup the download file. Any
suggestion or advise will be welcome...

Thanks in advance,
Louis

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic
&p=4073507#4073507

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode
=reply&p=4073507

__ ____ ____ ____ ____ ____ ____ ____ ____ ____
jboss-user mailing list
jboss-user@(protected)
https://lists.jboss.org/mailman/listinfo/jboss-user

©2008 junlu.com - Jax Systems, LLC, U.S.A.