4 Replies Latest reply on Jun 23, 2006 3:05 PM by ntsiii

    Problem with displaying exactly one item in a DataGrid

    ssreddy
      Hi,

      This is Sreedhar. I am working with Flex Builder 2 Beta 3, Java Server Pages, and SQL Server 2005. Currently, I am working on "Search based on Keyword". When I execute the search through the JSP, I am able to see the proper results. I am having a problem when displaying these results in a Flex DataGrid. If my search yields more than one result, the results are displayed in the DataGrid properly. However, if there is only one result, the DataGrid is blank.

      /******************The Query in JSP *************************/

      ResultSet rs = st.executeQuery("select User_FirstName, User_LastName, Podcast_Name, Rating, Category, FileType, Subscription_Fee, LogoPath, Sub_Category, Website_Url, FeedDescription, FilePath, Keywords from User_Info U, Podcast_Info P where U.User_ObjId = P.User_ObjId and P.Keywords like '%" +keyword+ "%'");

      /*************************************************************/
      We are using an ArrayCollection as follows:

      <mx:HTTPService id="selectdata" url=" http://localhost:8080/Essential2/SelectData.jsp"
      result="emp = new ArrayCollection(selectdata.lastResult.userinfo)">
      <mx:request>
      <key1>{key1.text}</key1>
      </mx:request>
      </mx:HTTPService>

      *Emp is the DataProvider for the DataGrid.

      I suspect the error is in the MXML, as the query executes correctly in JSP. If anyone has any suggestions, it would be greatly appreciated.

      Thanks & Regards,
      Sreedhar
        • 1. Re: Problem with displaying exactly one item in a DataGrid
          Level 7
          I think the problem is the call to the ArrayCollection constructor and
          the return type of the query.

          The ArrayCollection constructor takes an argument of type Array. I
          suspect that when the search yields more than one result, the query
          returns an Array. But when the query returns only one result, the query
          returns a String.

          You could try structuring your code like this:

          var queryResult:Object = selectdata.lastResult.userinfo;
          if (!(queryResult is Array)) {
          queryResult = new Array(queryResult);
          }
          emp = new ArrayCollection(queryResult);

          The key is that you must create an Array if your query result is a
          single value.

          -- Greg
          -- Adobe Flex Builder team


          ssreddy wrote:
          > Hi,
          >
          > This is Sreedhar. I am working with Flex Builder 2 Beta 3, Java Server
          > Pages, and SQL Server 2005. Currently, I am working on "Search based on
          > Keyword". When I execute the search through the JSP, I am able to see the
          > proper results. I am having a problem when displaying these results in a Flex
          > DataGrid. If my search yields more than one result, the results are displayed
          > in the DataGrid properly. However, if there is only one result, the DataGrid is
          > blank.
          >
          > /******************The Query in JSP *************************/
          >
          > ResultSet rs = st.executeQuery("select User_FirstName, User_LastName,
          > Podcast_Name, Rating, Category, FileType, Subscription_Fee, LogoPath,
          > Sub_Category, Website_Url, FeedDescription, FilePath, Keywords from User_Info
          > U, Podcast_Info P where U.User_ObjId = P.User_ObjId and P.Keywords like '%"
          > +keyword+ "%'");
          >
          > /*************************************************************/
          > We are using an ArrayCollection as follows:
          >
          > <mx:HTTPService id="selectdata"
          > url=" http://localhost:8080/Essential2/SelectData.jsp"
          > result="emp = new ArrayCollection(selectdata.lastResult.userinfo)">
          > <mx:request>
          > <key1>{key1.text}</key1>
          > </mx:request>
          > </mx:HTTPService>
          >
          > *Emp is the DataProvider for the DataGrid.
          >
          > I suspect the error is in the MXML, as the query executes correctly in JSP. If
          > anyone has any suggestions, it would be greatly appreciated.
          >
          > Thanks & Regards,
          > Sreedhar
          >
          • 2. Re: Problem with displaying exactly one item in a DataGrid
            ntsiii Level 3
            While I haven't verified this in 2.0, in 1.5 there was an issue where Flex was unable to differentiate between an array with a single element and an Object. The solution was to wrap the reference in the mx.utils.ArrayUtil.toArray() function.

            Since this still exists in 2.0 I would give it a try.

            Tracy
            • 3. Re: Problem with displaying exactly one item in a DataGrid
              ssreddy Level 1
              Hi,
              This is Sreedhar.
              Thanks for your reply.
              Now, I am able to display data in DataGrid based on a keyword search, even there is one maching record in my table.
              Now, I am trying to save entire Datagrid Items in to a table in the database by a Button Click.
              I am very thankful, if somebody helps me in this problem.

              Thanks & Regards,
              Sreedhar
              • 4. Re: Problem with displaying exactly one item in a DataGrid
                ntsiii Level 3
                This is a new topic, start a new thread.

                And say what you have tried so far.

                Tracy