Navigating to Detail page for subclass

2012-12-09
2013-03-04
  • Patrik Jonsson

    Patrik Jonsson - 2012-12-09

    Hi

    I am fairly new to OpenXava, love the tool and would need help.

    I have created a hierarchy of objects using OneToMany relationships.
    E.g. Organization OneToMany OrganizationElement

    I also use an inheritance hierarchy such as that Organization, Person and Office all extends OrganizationElement.

    When I show the detail of Organization, I would want to be able to click on a listed Person or Organization and have their respective specific detail view opened (e.g. Person Detail or Organization Detail).

    I have looked a good deal at some of the posts and have found some that seem to be about something like this, but not quite. My coding attempts all turn out fairly clumsy and it seems that this should be fairly straightforward.

    Also I wonder if there is a way to show all Collections of a Detail page as collapsed by default?

    Patrik

     
  • Javier Paniza

    Javier Paniza - 2012-12-11

    Hi Patrik,

    When I show the detail of Organization, I would want to be able to click on
    a listed Person or Organization and have their respective specific detail
    view opened (e.g. Person Detail or Organization Detail).

    By default, it work in that way, it open the detail into a dialog.
    Do you want to show it in a plain view in the same module or changing the module?
    Do you want that behavior for certain collection or for all the collections of your application.

    In any case you have to use @EditAction on the collection to define your own action. If you create this action generic enough would be nice if you contribute it to OpenXava. I think it's not difficult.

    Also I wonder if there is a way to show all Collections of a Detail page as
    collapsed by default?

    Good question! Try this code in an init action:

    getView().setFrameClose("mycollection", true);
    

    Does it work for you?
    Do you want the frame closed for a concrete module or for the entire application?


    Help others in this forum as I help you.
    Before posting a question search this forum for the answer,
    and read the OpenXava documentation in openxava.org.

     
    • Patrik Jonsson

      Patrik Jonsson - 2012-12-12

      Thanks for your prompt response Javier!

      In fact, I want to show the subclass Detail in a plain view.
      I was thinking that switching module would be the way to accomplish this.
      However, I have not been able to figure out two things:
      1. How to change module programmatically.
      2. How to find the specific subclass of the element being listed in a collection of another detail view. When I use getEntity on getCollectionElementView() I get the common superclass. How do I get the specific subclass?
      My idea was to do this for all modules of the entire application.

      Also, I was thinking about showing all collections of all details pages for the entire application as collapsed.

      Patrik

       
  • Javier Paniza

    Javier Paniza - 2012-12-14

    Hi Patrik,

    1. How to change module programmatically.

    Look at the wiki:
    http://openxava.wikispaces.com/controllers_en#Chapter%207:%20Controllers-Calling%20another%20module

    Another option is to change the view, just like the current action but instead of using showDialog() using showNewView()

    1. How to find the specific subclass of the element being listed in a collection

    Try getCollectionElementView().getModelName()

    My idea was to do this for all modules of the entire application.

    Look at the wiki:
    http://openxava.wikispaces.com/controllers_en#Chapter%207:%20Controllers-Override%20the%20default%20controllers%20%28new%20in%20v2.0.3%29

    I was thinking about showing all collections of all details pages for the entire application as collapsed.
    The way is add a on-init action to the controller to be used in your application. It's typical to use a custom controller instead of default Typical (as explained in the book).
    However, another option would be modify the code of the view to read from a property in xava.properties to show the collections collapse by default. If you choose this option would be nice if you contribute the code back to OpenXava.


    Ask OpenXava questions on StackOverflow

     
    • Patrik Jonsson

      Patrik Jonsson - 2012-12-15

      Thanks Javier,

      Maybe I am not doing it right, but getCollectionElementView().getModelName() does not seem to return the specific subclass, but only the superclass for which the list collection is defined. How can I get the specific subclass for the object that is present in the list?

      Patrik

       
      • Patrik Jonsson

        Patrik Jonsson - 2013-01-08

        Any ideas on this?

         
  • Javier Paniza

    Javier Paniza - 2013-01-11

    Hi Patrick,

    getModelName() should return the model of the current displayed object, not just the superclass. Maybe, you're calling the method before the view is populate.

    Put here some code and the need steps I have to follow in order to reproduce the case when the getModuleName() fails. I'll try it.


    Ask OpenXava questions on StackOverflow

     
    • Patrik Jonsson

      Patrik Jonsson - 2013-01-16

      Thanks Javier,
      You pointed me in the right direction.
      I was not using the super.execute() in the editaction. By including this it loads the values into the object and I get the right reference.
      Then I am able to show the object in the module. However, I have not figured out how to switch to Detail view. I use the this.setNextMode(DETAIL) in my EditAction, but it does not seem to set it to detail. Any thoughts?

      Regarding the collapsed Collections I got it working by adding a controller and ViewBaseAction with the following contents:

      public void execute() throws Exception {
          for (Object field: getView().getMetaMembers()){
      
              if (MetaCollection.class.isAssignableFrom(field.getClass())){
                  getView().setFrameClosed("Appname_" + getView().getModelName() +
                          "__frame_"+ ((MetaCollection) field).getName(), true);
                  }
      
      }
      }
      

      Regards,

      Patrik

       
  • Javier Paniza

    Javier Paniza - 2013-01-18

    Hi Patrik,

    I use the this.setNextMode(DETAIL) in my EditAction

    setNextMode(DETAIL) changes to detail mode, but if you call this from a EditAction of a collection you're already in detail mode, because all the collections are in detail mode.

    Do you want to show it in a plain view in the same module or changing the module? Tell me which option do you prefer and I'll give you some clue.


    Ask OpenXava questions on StackOverflow

     
    • Patrik Jonsson

      Patrik Jonsson - 2013-01-19

      I believe I wish to switch to the default Module that represents the selected entity, i.e. changinging the module.
      But I am not sure I understand which is preferred in this.

      Patrik

       
  • Javier Paniza

    Javier Paniza - 2013-01-21

    Hi Patrik,

    I believe I wish to switch to the default Module

    OK.
    If you have the book, read the section 11.3. It a complete example for changing module programatically and populating the view of target module.

    If you have not the book, have a look at the reference guide from wiki.


    Ask OpenXava questions on StackOverflow

     
    • Patrik Jonsson

      Patrik Jonsson - 2013-01-21

      Javier, I am impressed by your patience :-)

      In fact, my challenge is not so much the switching of module it seems, but rather getting it to detail mode programmatically.
      Right after the setBaseConditions I call the following in order to set Detail mode.
      this.setNextMode(getNextMode());
      This is the last part of the execute method.

      and then,
      public String getNextMode() {
      return IChangeModeAction.DETAIL;
      }

      However, it does not seem to go to Detail mode, but rather to List mode.

      Any thoughts?

      Patrik

       
  • Javier Paniza

    Javier Paniza - 2013-01-23

    Hi Patrik,

    it does not seem to go to Detail mode, but rather to List mode

    Yes, because your action lives in your current module, so all the changes you made is over the current mode, and when the action is executed completely it changes to the new module.

    There are several ways to solve your case. The one explained in the book is to define a only detail module just for this case, with a controller with a on-init action that reads from a session object that is populated in the calling action, more or less.


    Ask OpenXava questions on StackOverflow

     
    • Patrik Jonsson

      Patrik Jonsson - 2013-01-26

      Thanks Javier,

      I get this to work for most cases.
      I want to improve on a couple of things:
      1. How to achieve this when there is a reference from an Entity to Another Entity of the same type. E.g. Organization consists of Organizations. Then the module prohibits reentry. How can I still achieve to show Another entity in the view?
      2. How do I change the topmost title of the views? It does not seem to change even when I change the module?
      3. Is there a solution for a button for navigating back through a chain of views visited?

      Also, I realize that a whole deal of my problems stem from my lack of understanding of how the Modules, Tab, View interrelate. Perhaps this could be added to the Architecture description you have started? I would have loved to help, but do not know this well enough to contribute yet.

      Patrik

       
  • Javier Paniza

    Javier Paniza - 2013-02-25

    Hi Patrik,

    1. How to achieve this when there is a reference from an Entity to Another Entity of the same type. E.g. Organization consists of Organizations. Then the module prohibits reentry. How can I still achieve to show Another entity in the view?

    Create a new module for that same entity and call that module, indeed this technique is explained with detail in the section 11.3 of the book.

    1. How do I change the topmost title of the views? It does not seem to
      change even when I change the module?

    If you use another module, as I adviced you above, this module can have other title. On the other hand, if you want to modify the title by code use getManager().setModuleDescription("My module description").

    1. Is there a solution for a button for navigating back through a chain of views visited?

    If you're talking about views, use returnToPreviousView(), however if your navigating between module (and I think that you're doing this) create an IChangeModuleAction that returns PREVIOUS_MODULE for getNextModule(). Look at API doc.

    Perhaps this could be added to the Architecture description you have started?

    I don't know if that is exactly architecture, I think that the architecture is more related with the things behind the scene, while Tab, Modules and View are main concepts that an application developer have to know. Are you read the book?


    Help others in this forum as I help you.
    Before posting a question search this forum for the answer,
    and read the OpenXava documentation in openxava.org.

     
    • Patrik Jonsson

      Patrik Jonsson - 2013-03-01

      Thanks Jaview
      1. However, I fail to be able to enter other module. Here is the pattern how I defined the modules (I removed the leading < for all entries since it made the text not to show):
      module name="OrganizationDetail">
      model name="Organization"/>
      controller name="Typical"/>
      mode-controller name="DetailOnly"/>
      controller name="Init"/>
      /module>
      module name="OrganizationDetail1">
      model name="Organization"/>
      controller name="Typical"/>
      mode-controller name="DetailOnly"/>
      controller name="Init"/>
      /module>
      2. I am able to change the title (I can read it programmatically) but the browser fails to refresh it so it does not show? How can I programatically refresh the browser or else cause it to show?

      Patrik

       
      Last edit: Patrik Jonsson 2013-03-03
  • Javier Paniza

    Javier Paniza - 2013-03-04

    Hi Patrik,

    1. However, I fail to be able to enter other module

    Put here the Init controller definition, the Init actions code and the code of the action that navigates.

    1. I am able to change the title

    Yes, it's possible, because the external frame is not refreshed by AJAX. Within a portal this frame is drawn by the portal not by OX, so it's not easy to find a solution for this case, though we can use IForwardAction. Are you using Liferay?


    Help others in this forum as I help you.
    Before posting a question search this forum for the answer,
    and read the OpenXava documentation in openxava.org.

     
    Last edit: Javier Paniza 2013-03-04

Log in to post a comment.