jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • Mod4j: Modeling for Java using Domain Specific Languages
  • MODFORJ-86

Implement hashcode and equals for DTO objects

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Duplicate
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: DSL for Data Contract
  • Labels:
    None
  • Environment:
    Project using JSF (Richfaces), mod4j 1.0.0-beta-3
  • Testcase included:
    yes

Description

The project is using DTO objects in the presentation layer. Specifically:
"Spoken languages" are a business type. A language spoken by a person is modelled in the business layer.

In the presentation layer, this can be edited. Spoken languages can be added by selecting them from a drop-down. The spoken languages by a person are retrieved by a service call. Also, all possible values for spoken languages are retrieved.
All possible 'spoken languages' are put in <selectItem> objects:
SelectItem newItem = new SelectItem(taalDto, taalDto.getNaam());
The spoken languages by the person are stored in a DTO object.
The presentation layer:
<rich:inplaceSelect value="#{current.taal}">
<f:selectItems value="#{bewerkTalenBean.alleTalen}" />
</rich:inplaceSelect>

current is of type TaalNiveauDTO, which contains a reference to TaalDTO (current.taal)
The selectItems store the TaalDTO objects, retrieved through a "listAll" in the service layer.

For a TaalDTO object with matching id, the equals() method returns false. Therefore, the objects are not matched, and spoken languages by a person are not visible (unselected in the drop-down)

A workaround has been implemented (by manually matching the id of TaalDTO), but should not be necessary if the DTO contains an implementation of the equals() method.

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Hide
    Zip Archive
    testEquals.zip
    13/Mar/09 8:29 AM
    27 kB
    Dimar van Rietschoten
    1. XML File
      pom.xml 15 kB
    2. File
      TestEquals-dslModels/.../MANIFEST.MF 0.7 kB
    3. File
      TestEquals-dslModels/build.properties 0.1 kB
    4. File
      TestEquals-dslModels/.../SampleModel.crossx 1.0 kB
    5. File
      TestEquals-dslModels/.../SampleModel.busmod 0.1 kB
    6. File
      TestEquals-dslModels/.../mod4j.properties 1 kB
    7. File
      TestEquals-dslModels/.../SampleModel.sermod 0.2 kB
    8. File
      TestEquals-dslModels/.../SampleModel.crossx 1 kB
    9. File
      TestEquals-dslModels/.../SampleModel.dtcmod 0.2 kB
    10. File
      TestEquals-dslModels/.../SampleModel.crossx 1 kB
    11. File
      TestEquals-dslModels/.../SampleModel.busmod 0.1 kB
    12. File
      TestEquals-dslModels/.../mod4j.properties 1 kB
    13. File
      TestEquals-dslModels/.../SampleModel.sermod 0.2 kB
    14. File
      TestEquals-dslModels/.../SampleModel.dtcmod 0.2 kB
    15. XML File
      TestEquals-dslModels/pom.xml 4 kB
    16. XML File
      TestEquals-service/.../applicationContextBase.xml 3 kB
    17. XML File
      TestEquals-service/.../beanRefContext.xml 1 kB
    18. File
      TestEquals-service/.../org.eclipse.jdt.core.prefs 0.2 kB
    19. Java Source File
      TestEquals-service/.../SampleDtoTranslator.java 5 kB
    20. Java Source File
      TestEquals-service/.../SampleDto.java 1.0 kB
    21. Java Source File
      TestEquals-service/.../SampleServiceModelLocalServiceImplBase.java 4 kB
    22. Java Source File
      TestEquals-service/.../SampleServiceModelLocalService.java 2 kB
    23. XML File
      TestEquals-service/.../applicationContext.xml 1 kB
    24. Java Source File
      TestEquals-service/.../SampleServiceModelLocalServiceImpl.java 0.8 kB
    25. Java Source File
      TestEquals-service/src/.../TestEquals.java 0.5 kB
    26. XML File
      TestEquals-service/pom.xml 1 kB
    Download Zip
    Show
    Zip Archive
    testEquals.zip
    13/Mar/09 8:29 AM
    27 kB
    Dimar van Rietschoten

Issue Links

duplicates

New Feature - A new feature of the product, which has yet to be developed. MODFORJ-125 Add toString, equals, etc implementation to Dto'

  • Trivial - Cosmetic problem like misspelt words or misaligned text.
  • Resolved - A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.

Activity

  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Dimar van Rietschoten added a comment - 13/Mar/09 9:58 AM

Also would be beneficial for maintaining references in the presentation layer:
Object A references 'n' objects of type B.

References can be added in the view. The service is notified through removeFromXX and addToXX methods.

The view has responsibility to determine if an instance of B is new, changed or removed from A (to be able to use removeFrom and addTo methods)

If the DTO's implement equals, this could be somewhat easier:
List<B> existing = service.getBForA (a);
List<B< modifiedThroughView;

for (B b : modifiedThroughView) {
if (existing.contains(b)) { ... }
}

The contains relies on the B objects implementing hashcode & equals.

Show
Dimar van Rietschoten added a comment - 13/Mar/09 9:58 AM Also would be beneficial for maintaining references in the presentation layer: Object A references 'n' objects of type B. References can be added in the view. The service is notified through removeFromXX and addToXX methods. The view has responsibility to determine if an instance of B is new, changed or removed from A (to be able to use removeFrom and addTo methods) If the DTO's implement equals, this could be somewhat easier: List<B> existing = service.getBForA (a); List<B< modifiedThroughView; for (B b : modifiedThroughView) { if (existing.contains(b)) { ... } } The contains relies on the B objects implementing hashcode & equals.

People

  • Assignee:
    Jos Warmer
    Reporter:
    Dimar van Rietschoten
Vote (0)
Watch (0)

Dates

  • Created:
    13/Mar/09 8:29 AM
    Updated:
    30/Jul/09 5:53 AM
    Resolved:
    30/Jul/09 5:53 AM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.