1

我有一个名为“Company”的域对象,其中包含一组名为“Location”的域对象

我可以添加每个对象,并将位置关联到 Company 的父对象,但由于某种原因,位置对象表在 Company 页面中始终为空。我错过了什么?

位置类 -

@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);
    }

}

公司类别 -

@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;

}
4

1 回答 1

1

哇,我没有意识到它是延迟加载的,直到我单击 UI 下拉框中的“表格”选项才显示。

=]

于 2017-03-24T22:57:25.083 回答