1

I have a domain object called "Company" with a Set<> of domain object called "Location"

I can add objects of each, and associate a location to a parent object of Company, but for some reason the Location object table is always empty in the Company page. What am I missing?

Location class -

@javax.jdo.annotations.PersistenceCapable(schema = "todo", table = "Locations", identityType = IdentityType.DATASTORE)
@javax.jdo.annotations.DatastoreIdentity(strategy = javax.jdo.annotations.IdGeneratorStrategy.IDENTITY, column = "id")
@javax.jdo.annotations.Version(strategy = VersionStrategy.VERSION_NUMBER, column = "version")
@SuppressWarnings("serial")
public class Location extends AbstractDomainObject implements Comparable<Location> {

    public String title() {
        final TitleBuffer buf = new TitleBuffer();
        buf.append(getName());
        return buf.toString();
    }

    @Column(allowsNull = "false")
    @Property(editing = Editing.DISABLED)
    @Getter
    @Setter
    private Company company;

    @javax.jdo.annotations.Column(allowsNull = "false", length = 100)
    @Property(domainEvent = LocationNameDomainEvent.class, regexPattern = "\\w[@&:\\-\\,\\.\\+ \\w]*", editing = Editing.ENABLED)
    @Getter
    @Setter
    private String name;

    public static class LocationNameDomainEvent extends LocationPropertyDomainEvent<String> {
    }

    @javax.jdo.annotations.Column(allowsNull = "false", length = 100)
    @Property(domainEvent = LocationAddressDomainEvent.class, regexPattern = "\\w[@&:\\-\\,\\.\\+ \\w]*", editing = Editing.ENABLED)
    @Getter
    @Setter
    private String address;

    public static class LocationAddressDomainEvent extends LocationPropertyDomainEvent<String> {
    }

    @javax.jdo.annotations.Column(allowsNull = "true", length = 100)
    @Property(domainEvent = LocationAddress2DomainEvent.class, regexPattern = "\\w[@&:\\-\\,\\.\\+ \\w]*", editing = Editing.ENABLED)
    @Getter
    @Setter
    private String address2;

    public static class LocationAddress2DomainEvent extends LocationPropertyDomainEvent<String> {
    }

    @javax.jdo.annotations.Column(allowsNull = "false", length = 100)
    @Property(domainEvent = LocationCityDomainEvent.class, regexPattern = "\\w[@&:\\-\\,\\.\\+ \\w]*", editing = Editing.ENABLED)
    @Getter
    @Setter
    private String city;

    public static class LocationCityDomainEvent extends LocationPropertyDomainEvent<String> {
    }

    @javax.jdo.annotations.Column(allowsNull = "false", length = 2)
    @Property(domainEvent = LocationStateDomainEvent.class, regexPattern = "[A-ZA-Z]", editing = Editing.ENABLED)
    @Getter
    @Setter
    private String state;

    public static class LocationStateDomainEvent extends LocationPropertyDomainEvent<String> {
    }

    @javax.jdo.annotations.Column(allowsNull = "false", length = 5)
    @Property(domainEvent = LocationZipCodeDomainEvent.class, regexPattern = "[0-9]*5", editing = Editing.ENABLED)
    @Getter
    @Setter
    private String zipCode;

    public static class LocationZipCodeDomainEvent extends LocationPropertyDomainEvent<String> {
    }

    // region > events
    public static abstract class LocationPropertyDomainEvent<T> extends ToDoAppDomainModule.PropertyDomainEvent<Location, T> {
    }

    public static abstract class LocationActionDomainEvent extends ToDoAppDomainModule.ActionDomainEvent<Location> {
    }
    // endregion

    @Override
    public int compareTo(Location o) {
        // TODO Auto-generated method stub
        return String.valueOf(o).compareTo(this.name);
    }

}

Company Class -

@javax.jdo.annotations.PersistenceCapable(
        schema = "todo",
        table = "Company",
        identityType=IdentityType.DATASTORE)
@javax.jdo.annotations.DatastoreIdentity(
        strategy=javax.jdo.annotations.IdGeneratorStrategy.IDENTITY,
         column="id")
@javax.jdo.annotations.Version(
        strategy=VersionStrategy.VERSION_NUMBER, 
        column="version")
@javax.jdo.annotations.Uniques({
    @javax.jdo.annotations.Unique(
            name="Company_name_must_be_unique", 
            members={"name"})
})
@SuppressWarnings("serial")
public class Company extends AbstractDomainObject{

    public String title() {
        final TitleBuffer buf = new TitleBuffer();
        buf.append(getName());
        return buf.toString();
    }

    @javax.jdo.annotations.Column(allowsNull="false", length=100)
    @Property(
        domainEvent = CompanyNameDomainEvent.class,
        regexPattern = "\\w[@&:\\-\\,\\.\\+ \\w]*",
            editing = Editing.ENABLED
    )
    @Getter @Setter
    private String name;
    public static class CompanyNameDomainEvent extends CompanyPropertyDomainEvent<String> { }


    @javax.jdo.annotations.Column(allowsNull="false", length=100)
    @Property(
        domainEvent = CompanyAddressDomainEvent.class,
        regexPattern = "\\w[@&:\\-\\,\\.\\+ \\w]*",
            editing = Editing.ENABLED
    )
    @Getter @Setter
    private String address;
    public static class CompanyAddressDomainEvent extends CompanyPropertyDomainEvent<String> { }


    @javax.jdo.annotations.Column(allowsNull="true", length=100)
    @Property(
        domainEvent = CompanyAddress2DomainEvent.class,
        regexPattern = "\\w[@&:\\-\\,\\.\\+ \\w]*",
            editing = Editing.ENABLED
    )
    @Getter @Setter
    private String address2;
    public static class CompanyAddress2DomainEvent extends CompanyPropertyDomainEvent<String> { }


    @javax.jdo.annotations.Column(allowsNull="false", length=100)
    @Property(
        domainEvent = CompanyCityDomainEvent.class,
        regexPattern = "\\w[@&:\\-\\,\\.\\+ \\w]*",
            editing = Editing.ENABLED
    )
    @Getter @Setter
    private String city;
    public static class CompanyCityDomainEvent extends CompanyPropertyDomainEvent<String> { }


    @javax.jdo.annotations.Column(allowsNull="false", length=2)
    @Property(
        domainEvent = CompanyStateDomainEvent.class,
        regexPattern = "[A-ZA-Z]",
            editing = Editing.ENABLED
    )
    @Getter @Setter
    private String state;
    public static class CompanyStateDomainEvent extends CompanyPropertyDomainEvent<String> { }


    @javax.jdo.annotations.Column(allowsNull="false", length=5)
    @Property(
        domainEvent = CompanyZipCodeDomainEvent.class,
        regexPattern = "[0-9]*5",
            editing = Editing.ENABLED
    )
    @Getter @Setter
    private String zipCode;
    public static class CompanyZipCodeDomainEvent extends CompanyPropertyDomainEvent<String> { }


    @javax.jdo.annotations.Column(allowsNull="true", length=100)
    @Property(
        domainEvent = CompanyWebsiteDomainEvent.class,
        editing = Editing.ENABLED
    )
    @Getter @Setter
    private String website;
    public static class CompanyWebsiteDomainEvent extends CompanyPropertyDomainEvent<String> { }


    @javax.jdo.annotations.Column(allowsNull="false", length=12)
    @Property(
        domainEvent = CompanyPhoneNumberDomainEvent.class,
        editing = Editing.ENABLED
    )
    @Getter @Setter
    private String phoneNumber;
    public static class CompanyPhoneNumberDomainEvent extends CompanyPropertyDomainEvent<String> { }


    @javax.jdo.annotations.Persistent(table="CompanyLocations", mappedBy="company")
    @javax.jdo.annotations.Join(column="dependingId")
    @javax.jdo.annotations.Element(column="dependentId")
    private Set<Location> locations = new TreeSet<>();
    @Collection()
    public Set<Location> getLocations() {
        return locations;
    }
    public void setLocations(final Set<Location> locations) {
        this.locations = locations;
    }
    public void addToLocations(final Location location) {
        getLocations().add(location);
    }
    public void removeFromLocations(final Location location) {
        getLocations().remove(location);
    }

    @Action
    @ActionLayout(cssClassFa = "fa fa-plus")
    @MemberOrder(sequence = "5")
    public Company newLocation(
            @Parameter(maxLength=100)
            final String name, 
            @Parameter(maxLength=100)
            final String address, 
            @Parameter(maxLength=100)
            final String address2, 
            @Parameter(maxLength=100)
            final String city, 
            @Parameter(maxLength=2)
            final String state, 
            @Parameter(maxLength=5)
            final String zipCode){
        Location location = repository.instantiate(Location.class);
        location.setName(name);
        location.setAddress(address);
        location.setAddress2(address2);
        location.setCity(city);
        location.setState(state);
        location.setZipCode(zipCode);
        location.setCompany(this);
        repository.persistAndFlush(location);
        return addLocation(location);
    }
    @Programmatic
    public Company addLocation(final Location location) {
        // By wrapping the call, Isis will detect that the collection is modified
        // and it will automatically send CollectionInteractionEvents to the Event Bus.
        wrapperFactory.wrapSkipRules(this).addToLocations(location);
        repository.persistAndFlush(this);
        return this;
    }
    @Programmatic
    public Company removeLocation(final Location location) {
        // By wrapping the call, Isis will detect that the collection is modified
        // and it will automatically send a CollectionInteractionEvent to the Event Bus.
        wrapperFactory.wrapSkipRules(this).removeFromLocations(location);
        repository.persistAndFlush(this);
        return this;
    }


    //region > events
    public static abstract class CompanyPropertyDomainEvent<T> extends ToDoAppDomainModule.PropertyDomainEvent<Company, T> { }
    public static abstract class CompanyActionDomainEvent extends ToDoAppDomainModule.ActionDomainEvent<Company> { }
    //endregion



    @javax.inject.Inject
    WrapperFactory wrapperFactory;
    @Inject
    Locations locationService;
    @javax.inject.Inject
    RepositoryService repository;

}
Jeremy
  • 2,970
  • 1
  • 26
  • 50

1 Answers1

1

Wow, I didn't realize it was lazily loaded, and didn't show until I clicked the "Table" option in the dropdown box in the UI.

=]

Jeremy
  • 2,970
  • 1
  • 26
  • 50
  • You can use @CollectionLayout(defaultView="table"), or the equivalent in the Company.layout.xml. The idea is that this is extensible; there could be other views/visualizations of the set of domain objects. If you use the [isis addons](http://www.isisaddons.org), then there are views for calendars, maps etc. – Dan Haywood Mar 25 '17 at 11:25
  • Thanks Dan. I'm glad to get another opportunity to work with this framework again. – Jeremy Mar 26 '17 at 21:26