6 Replies Latest reply on Aug 2, 2007 5:59 PM by mgrouch

    Use Seam to generate XML documents

      What is the best way to generate XML documents (instead of html)
      from Seam beans?

      Thanks

        • 1. Re: Use Seam to generate XML documents
          tony.herstell1

          If the XML is to be a representation of the View then supply a different renderer that produces XML from each UI component in the server side component tree (JSF) and this will get called when JSF reaches the Render phase... or if you just want to create XML then look at something like JDom which is really nice to use?

          • 2. Re: Use Seam to generate XML documents

            Can I inject Seam beans into simple servlet? I could create XML myself
            I just need access to Seam scoped components in regular servlet.
            Are there any examples of injecting/outjecting Seam components into/from a servlet?

            • 4. Re: Use Seam to generate XML documents

              Thanks. This helps

              • 5. Re: Use Seam to generate XML documents

                Still having problems with injection.

                I've tried adding

                <web:context-filter url-pattern="*DataServlet"/>

                into components.xml

                'database' is not injected and the output from servlet is just

                <xml>Database=null</xml>


                'database' is injected fine into JSF pages, but not into servlet.

                import java.io.IOException;
                
                import javax.servlet.ServletException;
                import javax.servlet.http.HttpServlet;
                import javax.servlet.http.HttpServletRequest;
                import javax.servlet.http.HttpServletResponse;
                
                import org.hibernate.Session;
                import org.jboss.seam.annotations.In;
                import org.jboss.seam.annotations.Name;
                
                @Name("DataServlet")
                public class DataServlet extends HttpServlet {
                
                
                 @In(required=false)
                 private Session database;
                
                 public DataServlet() {
                 super();
                 }
                
                 protected String getAppType() {
                 return "application/xml";
                 }
                
                 @Override
                 protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
                 res.setContentType(getAppType());
                 res.getWriter().println("<xml>Database=" + database + "</xml>");
                 }
                }


                • 6. Re: Use Seam to generate XML documents

                  I've solved my problem by looking at the code of FeedServlet in Seam
                  wiki example. Injection doesn't work so I had to use
                  org.jboss.seam.Component.getInstance() calls within a servlet.