1

Recently,I used Apache Isis to build my DDD project。

Now,I have one entity object Customer,I think Customer may be have many value object,eg. CustomerContactInfomation.

public class Customer extends AbstractEntityObject{

    @Column(allowsNull = "false")
    @Getter
    private String name;

    @Column(allowsNull = "false")
    @Getter
    private String idcard;

    @Column(allowsNull = "false")
    @Getter
    private CustomerIdType idtype;

    public Customer(String name,String idcard,CustomerIdType idtype) {
        this.name = name;
        this.idcard = idcard;
        this.idtype = idtype;
    }

    @Persistent(mappedBy="customer",dependentElement="false")
    @Column(allowsNull="true")
    @Setter @Getter
    private CustomerContactInfomation contact;

}


public class CustomerContactInfomation {

    @PrimaryKey
    @Column(name = "customerId")
    @Getter
    private Customer customer;

    @Column(allowsNull = "true")
    @Setter @Getter
    private String phone;

}

CustomerContactInfomation just a Value Object,it can not have any action and should be maintained by Customer.

Customer-CustomerContactInfomation definitely is 1-1.

Now,how should I display CustomerContactInfomation in Customer and be able to edit CustomerContactInfomation?

Iseeu
  • 13
  • 4
  • also asked (in abbreviated form) on the Isis users mailing list, https://lists.apache.org/thread.html/79835126e5caba09e2a2726a0916073d8ca21f674005cd3aa0802f00@%3Cusers.isis.apache.org%3E. – Dan Haywood Aug 13 '17 at 16:57

1 Answers1

0

I'm not certain I'd describe CustomerContactInformation as a value object... it has a primary key so that makes it a persisted entity, and its phone property is mutable also.

But to put that to one side... I think it should be possible to get the effect you're after. As you've probably seen, the framework will render the Customer#contact property as a hyperlink to the CustomerContactInformation object. To allow its phone property to be maintained from the Customer, I suggest a simple action on Customer, eg:

@MemberOrder(named="contact", sequence="1")
public Customer updateContact(String newPhone) {
   this.contact.setPhone(newPhone);
   return this;
}

The @MemberOrder#name annotation will result in this button's action being rendered under the contact property.

HTH Dan

Dan Haywood
  • 2,215
  • 2
  • 17
  • 23