Announcement Announcement Module
Collapse
No announcement yet.
Generalization and JSP field order Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generalization and JSP field order

    Hello,
    I have used Roo for application containing generalization. Usually generated create/update/view JSPs show attributes in same order as defined in class *.java file. But when generalization is used it makes chaos in JSP.
    Example, fields are numbered:
    Code:
    enum type --class ~.enumeration.FooEnum
    enum constant --name CONSTANT1
    enum constant --name CONSTANT2
    
    entity --class ~.AbstractParent --abstract
    field string --fieldName field1
    field date --fieldName field2 --type java.util.Date
    field number --fieldName field3 --type java.lang.Float
    field number --fieldName field4 --type java.lang.Short
    
    entity --class ~.Child --extends ~.AbstractParent
    field string --fieldName field5
    field enum --fieldName field6 --type ~.enumeration.FooEnum
    field number --fieldName field7 --type java.lang.Integer
    On Children create JSP is field order:
    Code:
    Field3
    Field2
    Field5
    Field4
    Field7
    Field6
    Field1
    It makes no sense to me. Have anybody idea how to display fields in normal order (without direct editing of JSP)? Thank you

  • #2
    From the source code, it is ordering them by the order they are detected, which translates to the order they were created in.

    I modified your script a little to make it look more like the petclinic example and ran it and it produced the correct order:

    modified roo script:
    Code:
    project --topLevelPackage com.test.issue 
    persistence setup --provider HIBERNATE --database HYPERSONIC_PERSISTENT
    enum type --class ~.enumeration.FooEnum
    enum constant --name CONSTANT1
    enum constant --name CONSTANT2
    
    entity --class ~.domain.AbstractParent --abstract
    field string --fieldName field1
    field date --fieldName field2 --type java.util.Date
    field number --fieldName field3 --type java.lang.Float
    field number --fieldName field4 --type java.lang.Short
    
    entity --class ~.domain.Child --extends ~.domain.AbstractParent
    field string --fieldName field5
    field enum --fieldName field6 --type ~.enumeration.FooEnum
    field number --fieldName field7 --type java.lang.Integer
    
    
    controller all --package ~.web
    create.jspx:
    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <div xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:field="urn:jsptagdir:/WEB-INF/tags/form/fields" xmlns:form="urn:jsptagdir:/WEB-INF/tags/form" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:spring="http://www.springframework.org/tags" version="2.0">
        <jsp:directive.page contentType="text/html;charset=UTF-8"/>
        <jsp:output omit-xml-declaration="yes"/>
        <form:create id="fc_com_iaim_issue_domain_Child" modelAttribute="child" path="/children" render="${empty dependencies}" z="mPnlKwAEkFYUd5uVYnOxsVzVr9U=">
            <field:input field="field1" id="c_com_iaim_issue_domain_Child_field1" z="tusMFk5vNlU+r2qCcReNWiwEXAE="/>
            <field:datetime dateTimePattern="${child_field2_date_format}" field="field2" id="c_com_iaim_issue_domain_Child_field2" z="266Z1bxJrtWjZ+IvnP16XeyTwVM="/>
            <field:input field="field3" id="c_com_iaim_issue_domain_Child_field3" validationMessageCode="field_invalid_number" z="JvL2b1Kv70wF+T8UzrvOM8jgncc="/>
            <field:input field="field4" id="c_com_iaim_issue_domain_Child_field4" validationMessageCode="field_invalid_integer" z="rQEKgyGvr/EFdkUYW0DUfnQzJ7I="/>
            <field:input field="field5" id="c_com_iaim_issue_domain_Child_field5" z="pbXOPY97AeSN8xJsAXrKPuaT0KQ="/>
            <field:select field="field6" id="c_com_iaim_issue_domain_Child_field6" items="${fooenums}" path="fooenums" z="7nZAH5f8uFTvq7iMpFexcnThz9M="/>
            <field:input field="field7" id="c_com_iaim_issue_domain_Child_field7" validationMessageCode="field_invalid_integer" z="Pj/g1LBbv49fDchGBPtf47vE9mo="/>
        </form:create>
        <form:dependency dependencies="${dependencies}" id="d_com_iaim_issue_domain_Child" render="${not empty dependencies}" z="6hTEidjPETMgOe8ZPbEAQaei8Gk="/>
    </div>
    So not sure why yours order is different, I am using Roo 1.1.1.RELEASE, unless your creation order was different then the script you posted.

    You can change the order in the jspx, by changing the order in the domain object, then delete the create.jspx (or any of the files you want recreated) and when you start up roo again it will regenerate the create.jspx.

    So in this case, the AbstractParent fields are listed first in the jspx, based on the order in the domain object, then the Child fields are listed in the jspx, based on the order in the domain object.

    I edited the Java files and reversed the field order, deleted the create.jspx and had roo regenerate it:

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <div xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:field="urn:jsptagdir:/WEB-INF/tags/form/fields" xmlns:form="urn:jsptagdir:/WEB-INF/tags/form" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:spring="http://www.springframework.org/tags" version="2.0">
        <jsp:directive.page contentType="text/html;charset=UTF-8"/>
        <jsp:output omit-xml-declaration="yes"/>
        <form:create id="fc_com_iaim_issue_domain_Child" modelAttribute="child" path="/children" render="${empty dependencies}" z="mPnlKwAEkFYUd5uVYnOxsVzVr9U=">
            <field:input field="field4" id="c_com_iaim_issue_domain_Child_field4" validationMessageCode="field_invalid_integer" z="rQEKgyGvr/EFdkUYW0DUfnQzJ7I="/>
            <field:input field="field3" id="c_com_iaim_issue_domain_Child_field3" validationMessageCode="field_invalid_number" z="JvL2b1Kv70wF+T8UzrvOM8jgncc="/>
            <field:datetime dateTimePattern="${child_field2_date_format}" field="field2" id="c_com_iaim_issue_domain_Child_field2" z="266Z1bxJrtWjZ+IvnP16XeyTwVM="/>
            <field:input field="field1" id="c_com_iaim_issue_domain_Child_field1" z="tusMFk5vNlU+r2qCcReNWiwEXAE="/>
            <field:input field="field7" id="c_com_iaim_issue_domain_Child_field7" validationMessageCode="field_invalid_integer" z="Pj/g1LBbv49fDchGBPtf47vE9mo="/>
            <field:select field="field6" id="c_com_iaim_issue_domain_Child_field6" items="${fooenums}" path="fooenums" z="7nZAH5f8uFTvq7iMpFexcnThz9M="/>
            <field:input field="field5" id="c_com_iaim_issue_domain_Child_field5" z="pbXOPY97AeSN8xJsAXrKPuaT0KQ="/>
        </form:create>
        <form:dependency dependencies="${dependencies}" id="d_com_iaim_issue_domain_Child" render="${not empty dependencies}" z="6hTEidjPETMgOe8ZPbEAQaei8Gk="/>
    </div>
    As you can see, the Abstract fields 1-4 are reversed and put first, then the Child fields 5-7 are reversed and put next.

    Hope some of this might help you figure it out.
    Last edited by btlife; Feb 28th, 2011, 10:42 AM.

    Comment


    • #3
      Thank you! I have tested this script again with no change. I'm using 1.1.2.RELEASE. So I downloaded 1.1.1.RELEASE again and then it works.
      So there is some bug in 1.1.2. I will create a jira ticket for it.

      EDIT:
      ticket is here https://jira.springsource.org/browse/ROO-2184
      Last edited by Mamut; Feb 28th, 2011, 02:23 PM.

      Comment


      • #4
        I have tried to generate my application again and I realized all pages has this problem, not only whe generalization is used.
        Has anybody same problem with Roo 1.1.2.RELEASE?

        Comment


        • #5
          I fixed this already. Just grab a recent CI build and use that until 1.1.3 is released: http://static.springsource.org/downl...hp?project=ROO

          Comment

          Working...
          X