6 Replies Latest reply on May 1, 2006 5:51 AM by Christian Holm

    Mapping URL's to a seam actions.

    Mark French Newbie


      I am attempting to migrate an existing web app which currently uses cgi to serve up image content and also return server side created javascript to the client. What I was wondering if it was possible to map a url to a seam action to do this.



        • 1. Re: Mapping URL's to a seam actions.
          Gavin King Master

          What exactly do you mean? That was not enough information...

          • 2. Re: Mapping URL's to a seam actions.
            Mark French Newbie

            Basically the current ui makes a request to a cgi script for images and passes in some data. The script then returns image stream can this be replicated in seam. For example open url : localhost/images.cgi?id=1233. Hope this makes sense as I'm trying to avoid writing a servlet just for this purpose.

            • 3. Re: Mapping URL's to a seam actions.
              eekboom Newbie

              I am not sure if this is what you are after.
              Anyway here's a seam action I wrote to serve pdf files and avoid writing a servlet.
              I guess you should be able to simply change to other mime types like images.

              @Stateless(name = "ReportAction")
              public class ReportActionImpl implements ReportAction {
               private transient FacesContext _facesContext;
               @In(create = true)
               private ReportGenerator _reportGenerator;
               public String generateUserReport() {
               return generatePdfReport("http://foo.jrxml", "foo.pdf");
               private String generatePdfReport(String urlText, String fileName) {
               try {
               ExternalContext external = _facesContext.getExternalContext();
               HttpServletResponse response = (HttpServletResponse) external.getResponse();
               URL url = new URL(urlText);
               byte[] data = _reportGenerator.generatePdfReport(url);
               configureResponse(response, fileName, data.length);
               ServletOutputStream out = response.getOutputStream();
               return null;
               catch(IOException e) {
               throw new RuntimeException("Cannot generate report: ", e);
               private void configureResponse(HttpServletResponse response, String fileName, int length) {
               response.setHeader("Expires", "0");
               response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
               response.setHeader("Pragma", "public");
               response.addHeader("Content-disposition", "attachment; filename=\"" + fileName +"\"");

              • 4. Re: Mapping URL's to a seam actions.
                Mark French Newbie


                Thanks for that thats part of the puzzle I'm just not sure map a specific URL
                e.g. /ui/loadImage.cgi to always hit the action. Is possible using the faces-config.xml file or web.xml?



                • 5. Re: Mapping URL's to a seam actions.
                  Gavin King Master

                  Use a Seam page action (this functionality is only in CVS).

                   <page view-id="/ui/loadImage.jsp" action="#{my.action}"/>

                  • 6. Re: Mapping URL's to a seam actions.
                    Christian Holm Newbie

                    Would it be possible to enhance SEAM to use annotations to achieve this? It would be very nice if you could annotate your ejb method with something like