Results 1 to 9 of 9

Thread: Show ID field (Primary Key) in list.jspx

  1. #1
    Join Date
    Jun 2012
    Posts
    20

    Default Show ID field (Primary Key) in list.jspx

    I want to be able to show the id field (a primary key) of each entry in list.jspx and subsequently allow the user to enter their own id in create.jspx (down the road). Is this possible?

  2. #2
    Join Date
    Jan 2010
    Location
    Mislata - Valencia - Spain
    Posts
    162

    Default

    The id field is not show on direct engineer (make with entity and field commands) because value is auto generated.

    You can push-in the id property to your java class and remove the generated value annotation:

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Long id;
    Regards !
    Mario Martínez Sánchez
    Project Manager & Software Architect
    --------------------------
    Disid Technologies S.L.
    http://www.disid.com
    --------------------------
    gvNIX
    http://gvnix.googlecode.com
    http://www.gvnix.org

  3. #3
    Join Date
    Jun 2012
    Posts
    20

    Default

    I have the following for a very simple test. This is in test.java. Roo did automatically delete what is in test_roo_jpa_entity.java and the code in DB_managed. However when I run it on the server only the name is shown in list.jspx, still no ID field.

    @RooJavaBean
    @RooToString
    @RooJpaActiveRecord(versionField = "", table = "test")
    @RooDbManaged(automaticallyDelete = true)
    public class Test {

    @Id
    @Column(name = "testId")
    private Integer testId;

    @Column(name = "name", length = 30)
    private String name;

    //Getter & Setter for testId
    public Integer getTestId() {
    return this.testId;
    }

    public void setTestId(Integer testId) {
    this.testId = testId;
    }

    //Getter & Setter for Name
    public String getName() {
    return name;
    }

    public void setName(String name) {
    this.name = name;
    }
    }
    Any further advice? Thank you very much.

  4. #4
    Join Date
    Mar 2007
    Posts
    561

    Default

    You have to add the id-column manually to list.jspx

    e.g.

    <table:column id="c_com_foo_bar_id" property="id" z="-1"/>

  5. #5
    Join Date
    Jan 2010
    Location
    Mislata - Valencia - Spain
    Posts
    162

    Default

    Quote Originally Posted by spgmx View Post
    You have to add the id-column manually to list.jspx

    e.g.

    <table:column id="c_com_foo_bar_id" property="id" z="-1"/>
    With this solution, id value will be already auto generated.
    Mario Martínez Sánchez
    Project Manager & Software Architect
    --------------------------
    Disid Technologies S.L.
    http://www.disid.com
    --------------------------
    gvNIX
    http://gvnix.googlecode.com
    http://www.gvnix.org

  6. #6
    Join Date
    Mar 2007
    Posts
    561

    Default

    Quote Originally Posted by mmartinez View Post
    With this solution, id value will be already auto generated.
    It's just a new column in the HTML-table. Has nothing to do with generated keys or not. The table even doesn't care if it is an @Id field or not. Just a bean property.

  7. #7
    Join Date
    Jun 2012
    Posts
    20

    Default

    When I type the following into list.jspx

    <table:column id="c_com_mtc_test_Test_testId" property="testId" z="-1"/>
    I get an internal error. and that "No message found under code 'label_com_mtc_test_test_testid' for locale 'en_US'". The id field I am trying to show is called testId.
    Last edited by ericmc; Jul 2nd, 2012 at 08:08 AM.

  8. #8
    Join Date
    Mar 2007
    Posts
    561

    Default

    You have to add the message key 'label_com_mtc_test_test_testid' in your application.properties

  9. #9
    Join Date
    Jan 2010
    Location
    Mislata - Valencia - Spain
    Posts
    162

    Default

    Quote Originally Posted by spgmx View Post
    It's just a new column in the HTML-table. Has nothing to do with generated keys or not. The table even doesn't care if it is an @Id field or not. Just a bean property.
    This is to allow the user to enter their own id in create.jspx, this is a requirement of ericmc at first post message.
    Mario Martínez Sánchez
    Project Manager & Software Architect
    --------------------------
    Disid Technologies S.L.
    http://www.disid.com
    --------------------------
    gvNIX
    http://gvnix.googlecode.com
    http://www.gvnix.org

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •