5 Replies Latest reply on Nov 20, 2007 11:38 AM by xinhua

    How to integrate Ext with Seam using JSON

    fangzx

      I want to use json respone for Ext grid, can anyone explain how to use json in Seam?

        • 1. Re: How to integrate Ext with Seam using JSON
          damianharvey

          I had a play with the tree column component and used the json.org classes (which I jar'd up) and pumped the JSON out with a servlet using Beans that had a toJSONObject() method.

          I tried using XStream and Jettison but the JSON produced was not valid for Ext.

          It all worked when the page extension was .html but not when .xhtml. I'm not sure what caused this. I'll be looking into it again soon.

          Keen to hear how others have done this. I think Seam Remoting could be a better option. I know there are several people on the Ext forums using Seam as a backend.

          Cheers,

          Damian

          • 2. Re: How to integrate Ext with Seam using JSON
            xinhua

            Hi,
            I suggest to use Ext.data.ArrayReader not Json. I use a4j:jsFuction to get collection from server... For example, after create a grid object :

            Ext.onReady(a4j_loadRoleUsers);
            

            here a4j_loadRoleUsers is a4j:jsFuction defined BEFORE your grid js declaration. Maybe there is a better way to do this,but ,at least it works :)

            • 3. Re: How to integrate Ext with Seam using JSON
              fangzx

              Thanks for the reply.

              I will use servlet to build json response, and
              in servlet, We can call Seam Components to get grid data like this:

              public class SampleServlet extends HttpServlet {
              
               private UserService userService;
              
               private void createUserService() {
               userService = (UserService) Component.getInstance(UserService.class);
               }
              
               @Override
               public void doGet(HttpServletRequest request, HttpServletResponse response)
               throws ServletException, IOException {
               createUserService();
              
               PrintWriter out = response.getWriter();
              
               out.println("Hello World=" + userService.find("demo").getName());
              
               }
              }
              





              • 4. Re: How to integrate Ext with Seam using JSON
                damianharvey

                @Xinhua, that's an interesting way of doing it and feels more Seam-like than using a Servlet. Have you had any problems with xhtml and the ajax4jsf filters interfering with ExtJS?

                One advantage of the servlet approach is that the page loads with the grid/tree and then the call is made to the backend. Using a4j:jsFunction wouldn't the call be made to collect the data before the page is rendered - ie. introducing a delay in the page render?

                Cheers,

                Damian.

                • 5. Re: How to integrate Ext with Seam using JSON
                  xinhua

                  hi,damianharvey

                  my trick is , first create grid object with a "createGrid(data)" function, then use js:function to get collection from server and transfer it into "data",after that i use js:function "oncomplete" to call "createGrid(data)" to build the grid.

                  yes, i know js:Function is a very cheep way, :) but so far i didnot see any problem with xhtml and ajax4jsf filters.