isis

Apache Isis How to show Value Object


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?


Solution

  • 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