Menu

Transient collection displayed as Tree

JM
2011-09-19
2012-11-26
  • JM

    JM - 2011-09-19

    Hi,

    I am trying to show  a Tree based on calculated items of a transient class.

    If I show the calculated collection as a table, no problem.

    If I add the annotations to show it as a Tree, exceptions are thrown. It seams that OX tries to get data for items from the DB and there is not such a table.

    Code follows:

    The main module:

    package es.shin.oxtest.model;
    import java.math.BigDecimal;
    import java.util.Arrays;
    import java.util.Collection;
    import javax.persistence.Entity;
    import javax.persistence.Transient;
    import org.openxava.annotations.Editor;
    import org.openxava.annotations.Tree;
    import org.openxava.model.Identifiable;
    @Entity
    public class TheEntity extends Identifiable
    {
       private BigDecimal output;
       @Transient
        // No prob if these lines are commented
       @Editor( value="TreeView")
       @Tree( idProperties="id")
       //
    // Tree is built here
    //  A
    //  /A/B
    //  /A/C
       public Collection<MyTreeNode> getTree()
       {
          return Arrays.asList(
             new MyTreeNode( "A", this, ""),
             new MyTreeNode( "B", this, "/A"),
             new MyTreeNode( "C", this, "/A"));
       }
       public BigDecimal getOutput()
       {
          return output;
       }
       public void setOutput( BigDecimal output)
       {
          this.output= output;
       }
    }
    

    The tree node class, a transient one:

    package es.shin.oxtest.model;
    import javax.persistence.ManyToOne;
    import org.openxava.annotations.View;
    @View(members="label,path,id")
    // Nor Entity neither Embeddable
    public class MyTreeNode
    {
       // Not annotated as @Id so it is considered as transient
       private String id;
       private String path;
       @ManyToOne
       private TheEntity theEntity;
       public MyTreeNode( String id, TheEntity theEntity, String path)
       {
          setId( id);
          setTheEntity( theEntity);
          setPath( path);
       }
       public void setId(String id) {
          this.id = id;
       }
       public String getId() {
          return id;
       }
       public String getPath()
       {
          return path;
       }
       public void setPath( String path)
       {
          this.path = path;
       }
       public TheEntity getTheEntity()
       {
          return theEntity;
       }
       public void setTheEntity( TheEntity theEntity)
       {
          this.theEntity = theEntity;
       }
    }
    

    So, is it possible to show a transient tree?

    Thanks in advance for any help.

    • JM
     
  • Federico Alcantara

    Hi JM:

    TreeEditor by default uses a reader that points to data. You should write another editor pointing to a custom reader. Put in your editors.xml something like this:

     <editor name="MyTreeViewEditor" url="treeViewEditor.jsp">
                  <property name="reader" value="my.application.MyTreeViewReaderImpl" />
    </editor>
    

    Your reader implementation must implement ITreeViewReader, which is quite simple. Also, check the class code org.openxava.web.editors.TreeViewReaderImpl in OpenXava/src folder.

    Hope this helps,

    Federico

     
  • JM

    JM - 2011-09-19

    Seams really easy.

    But, I can not get it working.

    1.- Add the editor to my new file xava/editors.xml
    2.- Implement my.application.MyTreeViewReaderImpl
    3.- Anotate my tree member with @Editor( value="MyTreeViewEditor")

    .. and MyTreeViewReaderImpl is never used

    :(

    What am I missing?

    Thanks.

     
  • JM

    JM - 2011-09-20

    Hi,

    I think I found the problem:

    OpenXava 4.2.2 (2011-8-16)
    Class File ./org/openxava/web/editors/TreeView.java
    Line 511

    where it says

    clazz.isAssignableFrom( ITreeViewReader.class)
    

    should be

    ITreeViewReader.class.isAssignableFrom( clazz)
    

    Right?

    Cheers!

     
  • Federico Alcantara

    Hi JM:

    Can you put the editors.xml, and your classes code here?
    Also, when you run it, did you see any SEVERE message?

    Federico

     
  • Federico Alcantara

    Hi JM:

    clazz.isAssignableFrom( ITreeViewReader.class)

    Did you test it with the change, also for data? If it works please report it as a bug so that it can be fixed.

    Federico

     
  • JM

    JM - 2011-09-20

    I would not need to test it since

    AnyNonAbstractClass.isAssignableFrom( ITreeViewReader.class)
    

    is always false… right?

    Added as a bug.

    Cheers

     
  • JM

    JM - 2011-09-20

    Hi again:

    Even if I get a TransientTreeViewReaderImpl working, the code keeps trying to get the model from the DB (?) before asking the my transient reader for the data.

    I copy the exception below, thrown when the tree should start to be painted:

    SEVERE: WARNING! Impossible to create the condition for consult the list
    org.openxava.util.ElementNotFoundException: The reference theEntity does not exist in MyTreeNode 
        at org.openxava.model.meta.MetaModel.getMetaReference(MetaModel.java:395)
        at org.openxava.model.meta.MetaModel.isCalculated(MetaModel.java:1115)
        at org.openxava.mapping.ModelMapping.changePropertiesByColumns(ModelMapping.java:485)
        at org.openxava.mapping.ModelMapping.changePropertiesByColumns(ModelMapping.java:451)
        at org.openxava.tab.Tab.getSQLBaseCondition(Tab.java:180)
        at org.openxava.tab.Tab.createCondition(Tab.java:409)
        at org.openxava.tab.Tab.getCondition(Tab.java:382)
        at org.openxava.tab.Tab.createTableModel(Tab.java:350)
        at org.openxava.tab.Tab.getTableModel(Tab.java:330)
        at org.openxava.web.editors.TreeViewParser.parseGroups(TreeViewParser.java:160)
        at org.openxava.web.editors.TreeViewParser.parse(TreeViewParser.java:132)
        at org.apache.jsp.xava.editors.treeViewListEditor_jsp._jspService(treeViewListEditor_jsp.java:163)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
        at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
        at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
        at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
        at org.apache.jsp.xava.editors.collectionEditor_jsp._jspService(collectionEditor_jsp.java:735)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    ...
    

    Thanks for any hint.

     
  • JM

    JM - 2011-09-20

    Hi,

    A bit more info, just in case it could facilitate any response to my questions.

    TreeViewParser.parseGroups()
    

    tries to build a TableModel asking the database, in order to initialize the ITreeViewReader, even if the model is transient (as it is now the case)

    Cheers

     
  • Federico Alcantara

    Hi JM:

    It is definitively a bug. Meanwhile, you can try to fix it in your copy, and submit the code changes. I browsed through the TreeViewParser.parseGroups() method and it seems that Tab might be the one trying to read from data. Try to make it work without the tree annotations and editor. When you have it working, then add the tree annotations and editors.

    Hope this helps,

    Federico

     

Log in to post a comment.