Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    TreeModelType.CHILDREN JPA Treegrid

    Hi.
    I have a problem with the JPA, Datasource or TreeGrid if i use TreeModelType.Children. My problem is, that the Treegrid shows the Elements not as tree. All Elements are one underneath the other. Which settings are correct or what is wrong? Here is my code.

    Code:
    final DataSource treeDS = DataSource.get("tree_DataSource");
    final Tree tree = new Tree();
    tree.setModelType(TreeModelType.CHILDREN);
    tree.setChildrenProperty("childrenTreeNodes");	
    treeGrid = new TreeGrid();
    treeGrid.setData(tree);
    treeGrid.setAutoFetchData(true);  
    treeGrid.setDataSource(treeDS);   
    	        ...
    Code:
    <DataSource
        ID="tree_DataSource"
        serverConstructor="com.isomorphic.jpa.JPADataSource"
        beanClassName="com.detection.smiths.eapcfg.server.persistence.Tree">
        
        <fields>
            <field name="treeNodeId"     type="sequence" hidden="true"   primaryKey="true" />
            <field name="childrenTreeNodes" multiple="true" type="tree_DataSource"/> 
            <field name="nodeName"   type="text"     title="Name"    required="true"/>
        </fields>
    </DataSource>
    Code:
    @Entity
    @Table (name="Tree")
    public class Tree
        implements Serializable
    {
     
    
        @Id
        @Column (nullable = false)
        @GeneratedValue (strategy = GenerationType.IDENTITY)
        private Long treeNodeId;
      
        @Column (nullable = false)
        private String nodeName;
    
        @JoinColumn
        private List<Tree> childrenTreeNodes;
    
        public Tree ()
        {
        }
    
        @Override
        public String toString ()
        {
            return getClass().getName()
                   + "["
                   + "childrenTreeNodes=" + ((getChildrenTreeNodes() == null) ? "null" : getChildrenTreeNodes().toString())
                   + ", "
                   + "nodeName=" + ((getNodeName() == null) ? "null" : getNodeName().toString())
                   + "]";
        }
    ....
    Code:
    final DataSource treeDS = DataSource.get("tree_DataSource");
    Record newRecord = new Record();
    Record newRecord2 = new Record();
    Record[] tl=new Record[1];
    tl[0]=newRecord2;
    
    newRecord.setAttribute("nodeName", "A")
    newRecord.setAttribute("childrenTreeNodes", tl);
    newRecord2.setAttribute("nodeName", "B");
    newRecord2.setAttribute("childrenTreeNodes", new Record[0]);
    
    treeDS.addData(newRecord);
    Last edited by bnr; 14 Jun 2012, 12:52.

    #2
    Your DataSource is a kind of nonsense mix of what you'd want for modelType:children (multiple:true, childrenProperty) or the default of modelType:parent (foreignKey). You should probably re-read the Tree DataBinding overview to get clear on the different approaches.

    The modelType:children approach is not usually the easier one, but if you continue with it, the key thing needed for troubleshooting is the response from your server, as shown in the RPC tab of the Developer Console.

    Comment


      #3
      Hi, sorry for the funny DataSource. That was a trial-and-error DataSource. I have changed the DataSource and think, that was right. The error says something else. I'm not deep enough in the smartGWT stuff to understand the problem or the error output. I hope you can get me support again.

      Code:
      === 2012-06-14 22:10:59,071 [l0-0] DEBUG XML - Parsed XML from /Users/bnr/Documents/workspace/EAPcfg/war/ds/tree_DataSource.ds.xml: 2ms
      === 2012-06-14 21:51:50,038 [l0-0] ERROR DataSourceLoader - Exception while attempting to load a DataSource
      java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
      	at java.util.ArrayList.RangeCheck(ArrayList.java:547)
      	at java.util.ArrayList.get(ArrayList.java:322)
      	at com.isomorphic.datasource.DataSource.getPrimaryKey(DataSource.java:773)
      	at com.isomorphic.datasource.BasicDataSource.init(BasicDataSource.java:330)
      	at com.isomorphic.jpa.JPADataSource.init(JPADataSource.java:274)
      	at com.isomorphic.datasource.DataSource.initialize(DataSource.java:374)
      	at com.isomorphic.datasource.BasicDataSource.fromConfig(BasicDataSource.java:158)
      	at com.isomorphic.datasource.DataSource.fromConfig(DataSource.java:359)
      	at com.isomorphic.datasource.FileSystemDSRepo.loadDS(FileSystemDSRepo.java:110)
      	at com.isomorphic.datasource.DataSource.forName(DataSource.java:178)
      	at com.isomorphic.datasource.DataSource.forName(DataSource.java:170)
      	at com.isomorphic.datasource.DataSource.forName(DataSource.java:165)
      	at com.isomorphic.datasource.PoolableDataSourceFactory.makeUnpooledObject(PoolableDataSourceFactory.java:95)
      	at com.isomorphic.datasource.PoolableDataSourceFactory.makeObject(PoolableDataSourceFactory.java:102)
      	at com.isomorphic.pool.PoolManager.borrowObject(PoolManager.java:82)
      	at com.isomorphic.datasource.DataSourceManager.getDataSource(DataSourceManager.java:87)
      	at com.isomorphic.servlet.DataSourceLoader.processRequest(DataSourceLoader.java:109)
      	at com.isomorphic.servlet.DataSourceLoader.doGet(DataSourceLoader.java:83)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
      	at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
      	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
      	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
      	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
      	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
      	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
      	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      	at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
      	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      	at org.mortbay.jetty.Server.handle(Server.java:324)
      	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
      	at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829)
      	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
      	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
      	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
      	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
      	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
      === 2012-06-14 21:51:50,041 [l0-0] ERROR DataSourceLoader - Top-level servlet error: 
      javax.servlet.ServletException: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
      	at java.util.ArrayList.RangeCheck(ArrayList.java:547)
      Last edited by bnr; 14 Jun 2012, 12:11.

      Comment


        #4
        This indicates you have not declared a primaryKey.

        Comment


          #5
          Ok, I have add now a primary key to the data source. The problem is at present the same. Here is a Screen from my problem. You can see in the log that Tree B is in the childrenList.

          Code:
          === 2012-06-14 22:56:01,734 [0-11] INFO  RequestContext - URL: '/EAPcfg_js/sc/IDACall', User-Agent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:7.0.1) Gecko/20100101 Firefox/7.0.1': Moz (Gecko) with Accept-Encoding header
          === 2012-06-14 22:56:01,737 [0-11] DEBUG XML - Parsed XML from (in memory stream): 2ms
          === 2012-06-14 22:56:01,741 [0-11] DEBUG RPCManager - Processing 1 requests.
          === 2012-06-14 22:56:01,742 [0-11] DEBUG RPCManager - Request #1 (DSRequest) payload: {
              values:{
                  nodeName:"A",
                  nodeTyp:"category",
                  childrenTreeNodes:[
                      {
                          nodeName:"B",
                          nodeTyp:"category",
                          childrenTreeNodes:[
                          ]
                      }
                  ]
              },
              operationConfig:{
                  dataSource:"tree_DataSource",
                  operationType:"add"
              },
              appID:"builtinApplication",
              operation:"tree_DataSource_add",
              oldValues:{
                  nodeName:"A",
                  nodeTyp:"category",
                  childrenTreeNodes:[
                      {
                          nodeName:"B",
                          nodeTyp:"category",
                          childrenTreeNodes:[
                          ]
                      }
                  ]
              },
              criteria:{
              }
          }
          === 2012-06-14 22:56:01,742 [0-11] INFO  IDACall - Performing 1 operation(s)
          === 2012-06-14 22:56:01,742 [0-11] DEBUG AppBase - [builtinApplication.tree_DataSource_add] No userTypes defined, allowing anyone access to all operations for this application
          === 2012-06-14 22:56:01,742 [0-11] DEBUG AppBase - [builtinApplication.tree_DataSource_add] No public zero-argument method named '_tree_DataSource_add' found, performing generic datasource operation
          === 2012-06-14 22:56:01,743 [0-11] DEBUG JPADataSource - [builtinApplication.tree_DataSource_add] Auto-joining transactions.
          === 2012-06-14 22:56:01,743 [0-11] DEBUG JPADataSource - [builtinApplication.tree_DataSource_add] Creating EntityManager, starting transaction and setting it to RPCManager.
          === 2012-06-14 22:56:01,744 [0-11] DEBUG DSRequest - [builtinApplication.tree_DataSource_add] Clobbering existing FreeResourcesHandler of type 'com.isomorphic.jpa.JPADataSource' with a 'com.isomorphic.jpa.JPADataSource'
          === 2012-06-14 22:56:01,745 [0-11] DEBUG JPADataSource - [builtinApplication.tree_DataSource_add] Executing add.
          Hibernate: 
              select
                  tree0_.treeNodeId as treeNodeId27_,
                  tree0_.nodeName as nodeName27_,
                  tree0_.nodeTyp as nodeTyp27_ 
              from
                  Tree tree0_ 
              where
                  tree0_.treeNodeId=?
          Hibernate: 
              insert 
              into
                  Tree
                  (treeNodeId, nodeName, nodeTyp) 
              values
                  (null, ?, ?)
          Hibernate: 
              call identity()
          Hibernate: 
              insert 
              into
                  Tree
                  (treeNodeId, nodeName, nodeTyp) 
              values
                  (null, ?, ?)
          Hibernate: 
              call identity()
          === 2012-06-14 22:56:01,756 [0-11] DEBUG RPCManager - Content type for RPC transaction: text/plain; charset=UTF-8
          === 2012-06-14 22:56:01,756 [0-11] DEBUG JPADataSource - Committing transaction for 1 queued operation(s).
          Hibernate: 
              update
                  Tree 
              set
                  childrenTreeNodesID=? 
              where
                  treeNodeId=?
          === 2012-06-14 22:56:01,759 [0-11] WARN  DSResponse - Attempted to call getRecord() on a DSResponse with null DataSource
          === 2012-06-14 22:56:01,759 [0-11] DEBUG RPCManager - non-DMI response, dropExtraFields: false
          === 2012-06-14 22:56:01,762 [0-11] DEBUG JPADataSource - Releasing entity manager.
          Attached Files

          Comment


            #6
            So again - the thing to look at is the RPC tab in the Developer Console.

            Comment


              #7
              A, ok, nice tool.

              Add a new Record (RPC-Request Tab)
              Code:
              {
                  "actionURL":"http://127.0.0.1:8888/EAPcfg_js/sc/IDACall", 
                  "showPrompt":true, 
                  "transport":"xmlHttpRequest", 
                  "promptStyle":"cursor", 
                  "bypassCache":true, 
                  "data":{
                      "values":{
                          "nodeName":"A", 
                          "nodeTyp":"category", 
                          "childrenTreeNodes":[
                              {
                                  "nodeName":"B", 
                                  "nodeTyp":"category", 
                                  "childrenTreeNodes":[
                                  ]
                              }
                          ]
                      }, 
                      "operationConfig":{
                          "dataSource":"tree_DataSource", 
                          "repo":null, 
                          "operationType":"add"
                      }, 
                      "appID":"builtinApplication", 
                      "operation":"tree_DataSource_add", 
                      "oldValues":{
                          "nodeName":"A", 
                          "nodeTyp":"category", 
                          "childrenTreeNodes":[
                              {
                                  "nodeName":"B", 
                                  "nodeTyp":"category", 
                                  "childrenTreeNodes":[
                                  ]
                              }
                          ]
                      }, 
                      "streamResults":null, 
                      "exportToFilesystem":null, 
                      "exportToClient":null
                  }
              }
              Add a new Record (RPC Response Tab)
              Code:
              [
                  {
                      data:{
                          childrenTreeNodes:[
                              {
                                  childrenTreeNodes:[
                                  ], 
                                  nodeName:"B", 
                                  nodeTyp:"category", 
                                  treeNodeId:1
                              }
                          ], 
                          nodeName:"A", 
                          nodeTyp:"category", 
                          treeNodeId:2
                      }, 
                      invalidateCache:false, 
                      isDSResponse:true, 
                      operationType:"add", 
                      queueStatus:0, 
                      status:0
                  }
              ]

              Refresh the TreeGrid (RAW Response)
              Code:
              [
                  {
                      data:[
                          {
                              childrenTreeNodes:[
                              ], 
                              nodeName:"B", 
                              nodeTyp:"category", 
                              treeNodeId:1
                          }, 
                          {
                              childrenTreeNodes:[
                                  {
                                      childrenTreeNodes:[
                                      ], 
                                      nodeName:"B", 
                                      nodeTyp:"category", 
                                      treeNodeId:1
                                  }
                              ], 
                              nodeName:"A", 
                              nodeTyp:"category", 
                              treeNodeId:2
                          }
                      ], 
                      endRow:2, 
                      invalidateCache:false, 
                      isDSResponse:true, 
                      operationType:"fetch", 
                      queueStatus:0, 
                      startRow:0, 
                      status:0, 
                      totalRows:2
                  }
              ]
              Last edited by bnr; 14 Jun 2012, 14:34.

              Comment


                #8
                The data looks good, going back to your code, you're calling setData() with a Tree instance, but your autoFetchData:true immediately wipes this out, because fetchData() creates a tree.

                You can either:

                1. set childrenProperty="true" on the "childrenTreeNodes" DataSourceField to mark it as the tree property for any component using this DataSource (best approach)

                OR

                2. correctly set the childrenProperty using setDataProperties() instead of setData().

                Comment

                Working...
                X