Announcement Announcement Module
Collapse
No announcement yet.
Is using domain objects as view/form bean best practice ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is using domain objects as view/form bean best practice ?

    Is using domain objects in view layer as view bean/ form bean best practice.

    Currently we are using following pattern

    a) view beans for displaying data and getting data from form
    b) domain objects in service and DAO layer
    c) In controller we are converting view beans to domain object and vice versa.
    For mapping we are using dozer
    d) structure of domain objects and view beans/ form beans are similar ( not much difference)

    We have following options
    a) Remove view bean/form beans and directly use domain objects as view bean/ form beans. (where view bean and domain object have one to one mapping)
    b) use view beans only if required. (use view beans only when additional fields are required from user and which cannot be part of domain object directly or for getting data for which corresponding domain object does not exist such as search critieria )

  • #2
    c) In controller we are converting view beans to domain object and vice versa.
    For mapping we are using dozer
    What do you mean with view beans?

    Spring MVC let you use your domain object in your view, for example working with the <form> tag, Spring MVC and even Spring Web Flow can work with JSR 303 or if you prefer the classic way, with the Validation interface, even Spring 3.0.x series has better options like converters and formatters.

    Normally I have a Domain Object used like Entity for Hibernate and passed throughout the all layers, view, controller, model

    Could you expand what specific situation you want resolve?

    Comment


    • #3
      Further detail on enforced usage of view-bean and domain object seperation

      Even I'm facing similar dilemma. I've a hibernate backed Subscriber class which maintains an ordered collection of RechargeTransaction objects in a map. The relation between these two classes is bi-directional and the RechargeTransaction class has only one constructor which takes a subscriber as argument. This field is mapped as insertable but not updatable, hence there's no setter for the subscriber property of RechargeTransaction class. As per my requirement, every recharge has to be confirmed by the subscriber through a UI. Therefore, I'm displaying a composite page bound to my subscriber instance via spring3 form binding and the transactions are displayed in a table with checkbox against the ones which are not yet confirmed and/or rejected by the subscriber.

      I hope you understand the problem now. I can't directly bind my submitted parameters back to RechargeTransaction unless I provide a zero argument constructor and setter for subscriber. But doing that violates my domain principle. Therefore I'm forced to use a helper view-bean class with default zero argument constructor and public getters/setters for all fields (which can be input). and I've to write a custom converter which converts from my view-bean class to my domain and vice-versa. Effectively that means, Instead of creating three classes, one for controller and two for domain objects (RechargeTransaction and Subscriber), in effect I'm forced to create n classes, one for controller, two for converters for each domain class (one from view-bean to domain converter and other the opposite)(for subscriber and RechargeTransaction) domain class, and two domain classes.

      With my limited knowledge of spring data binding, I'm forced to either create a myriad of classes or use custom data binding in controller which takes out the FUN part from the whole solution.

      Please provide feedback and/or helpful pointers.

      Comment


      • #4
        I have a Domain Object used like Entity for Hibernate and passed throughout the all layers

        Comment

        Working...
        X