2 Replies Latest reply on Apr 29, 2009 5:34 AM by Joshua Davis

    Emitting XML

    Bob Corcoran Newbie

      Is it possible to emit XML from a Seam application? We are using the Google Search Appliance and we would like to use a bean in our existing Seam application as an external provider for one of our GSA One Module's. Normally, we would write a servlet and create the XML in the doGet method. But I would like to use Seam, if possible, without having to write another servlet, since the EJB we need to access is in the EAR that makes up our Seam application.

        • 1. Re: Emitting XML
          Bob Corcoran Newbie
          Here's the way I ended up doing it - in case anybody's interested:

          FacesContext context = FacesContext.getCurrentInstance();
                          HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
                          String query = request.getParameter("query");
                          HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
                          Document xmlout = new Document(new Element("OneBoxResults"));
             //  more JDOM code here...then...
                          try {
                                  PrintWriter out = response.getWriter();
                                  XMLOutputter outputter = new XMLOutputter();
                          } catch (IOException e) {
                                  // TODO Auto-generated catch block

          and in pages.xml:

          <page view-id="/gsa.xhtml">
                  <action execute="#{groupsGSAHandler.gsaSearch()}"/>              

          Note that the view-id "/gsa.xhtml" is only a place holder; there is no such file.
          • 2. Re: Emitting XML
            Joshua Davis Expert

            Have you tried using the contentType attribute of the f:view tag?

            <f:view xmlns:f="http://java.sun.com/jsf/core"
            blah blah... xml with EL markup

            That would set the content type for you.   We use this to make JNLP files for Java Web Start, among other things.