Announcement Announcement Module
Collapse
No announcement yet.
switching between entities Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • switching between entities

    I was just wondering what you recommend as the best way to switch between entities? Suppose I create a person entity, add a couple fields, then add a Contact entity add a couple fields to that, but then want to switch back to Person to continue adding fields to that. I can basically try to re-create the entity, it gives an error saying that it already exists but then appears to be back in the Person context. This works, but I was just curious if there was a way to do this w/out the error or if it even matters...

  • #2
    You are probably looking for the --class attribute in the field command. This lets you define to which target type the field should be added to. By default, if you don't add the --class attribute Roo will add the field to the last entity it has used (as indicated on the left hand side in the Roo shell).

    Comment


    • #3
      yeah I'm aware of the --class option, but i would like a way to just switch the roo context back to the Person class so i can add a bunch more fields w/out having to put the --class at the end of each one. not a huge deal since the entity command for an existing class works that way...

      Comment


      • #4
        The context automatically switches to the entity defined by class until you use --class again:

        Code:
        ~.Ent2 roo> field string --fieldName test --class ~.Ent1
        Managed SRC_MAIN_JAVA/com/foo/Ent1.java
        Created SRC_MAIN_JAVA/com/foo/Ent1_Roo_JavaBean.aj
        Managed SRC_MAIN_JAVA/com/foo/Ent1_Roo_ToString.aj
        ~.Ent1 roo> field string test2
        Managed SRC_MAIN_JAVA/com/foo/Ent1.java
        Managed SRC_MAIN_JAVA/com/foo/Ent1_Roo_JavaBean.aj
        Managed SRC_MAIN_JAVA/com/foo/Ent1_Roo_ToString.aj
        ~.Ent1 roo> field string --fieldName test --class ~.Ent2
        Managed SRC_MAIN_JAVA/com/foo/Ent2.java
        Created SRC_MAIN_JAVA/com/foo/Ent2_Roo_JavaBean.aj
        Managed SRC_MAIN_JAVA/com/foo/Ent2_Roo_ToString.aj
        ~.Ent2 roo> field string test2
        Managed SRC_MAIN_JAVA/com/foo/Ent2.java
        Managed SRC_MAIN_JAVA/com/foo/Ent2_Roo_JavaBean.aj
        Managed SRC_MAIN_JAVA/com/foo/Ent2_Roo_ToString.aj
        I believe this is what you are looking for?

        Comment


        • #5
          ah ok i see, cool. yeah that works

          Comment


          • #6
            Although this thread is rather old now the information may still be of some help to some spring roo newbies like me:
            in the roo console enter the command
            focus
            then hit TAB to make the option --class appear and enter the class name, as in
            roo> focus --class com.apringsource.roo.pizzashop.domain.Pizza
            or
            roo> focus --class ~.Pizza

            Comment

            Working...
            X