« Return to Thread: DWR - obtaining a path in remote method

Re: DWR - obtaining a path in remote method

by JBuilderDoug :: Rate this Message:

Reply to Author | View in Thread


David Marginian-3 wrote:
Have you tried using the FacesExtensionFilter?  I don't use JSF but it
looks like this may give you access to the FacesContext:
http://directwebremoting.org/dwr/server/jsf

Depending on what version of DWR you are using the docs may be outdated,
the package of the filter has changed:
org.directwebremoting.faces.FacesExtensionFilter

Look at the source of the class to see if it will help you out.

JBuilderDoug wrote:
> I have a retrieve button on my form that calls a javascript that sends a
> request back to my application on the server.  The server method gets
> information from a MySQL database and sends it back as a string [] to the
> javascript.  The java script parses the string and populates fields on the
> form.  All well and good.
>
> Now I need for the server method to retrieve the text data and also retrieve
> and image (BLOB) from MySQL, write it to a file, then send the filename back
> with the other text data for display.
>
> My problem is that (I'm using JSF) that the DWR method in my application on
> the server is not privvy to FacesContext (which makes sense).  My directory
> is images/<filename>, but that's a relative path.  If I wrote to
> images/<filename>, it would try to write to an "images" directory under
> glassfish\bin (since I'm deployed under glassfish) and that's the literal
> current directory.
>
> I need to get the real path to write the image file (something like
> c:\glassfish\domains\domain1\autodeploy\<my app name>\images.
>
> Then what I can pass back to the javascript is simply images\<filename>
>
> Surely, there's some context I can hook into once the javascript gets back
> to the server?
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@dwr.dev.java.net
For additional commands, e-mail: dev-help@dwr.dev.java.net
I solved this problem with some dwr stuff... here's how.  Turns out it didn't solve my ultimate problem however.

import org.directwebremoting.WebContext;
import org.directwebremoting.WebContextFactory;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
.
.
.
        java.sql.Blob b = users.getUserImage();  // retrieve BLOB from MySQL
        byte [] ba = b.getBytes(1, (int)b.length());  // put it in a byte []
        WebContext wctx = WebContextFactory.get();  // Get the context
             HttpSession session = wctx.getSession();  // Get the session
             HttpServletRequest request = wctx.getHttpServletRequest();  // Get the http request
        String sPath = (session.getServletContext().getRealPath(request.getContextPath()));
        sPath = sPath + "/images/" + users.getUsername() + ".jpg";
        File f = new File(sPath);
        FileOutputStream fos = new FileOutputStream(f);
        fos.write(ba);
        fos.close();

All of the text fields are returned to the javascript along with "images/<username>.jpg" which I innerHTML into the page, but since it doesn't refresh, the image never shows up.

I don't know how to force that read without a page refresh.   Maybe DWR/AJAX doesn't solve all problems.

 « Return to Thread: DWR - obtaining a path in remote method