Details
-
Type:
Improvement
-
Status:
Resolved
-
Priority:
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.
Issue Links
- duplicates
-
MODFORJ-125
Add toString, equals, etc implementation to Dto'
-
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.