isis

Apache Isis: @Property(editing = Editing.ENABLED) doesn't work for ViewModels


I added a property to ViewModel and marked it with Editing.ENABLED.

@DomainObject(
        nature = Nature.VIEW_MODEL,
        objectType = "homepage.HomePageViewModel"
)
public class HomePageViewModel {

    @Setter @Getter
    @Property(editing = Editing.ENABLED)
    private String editableField;

}

But this field is not editable on UI: ViewModel property Editing.ENABLED

But it works fine for SimpleObject: Simple DomainObj property Editing.Enabled

Does it work correctly for ViewModel? Maybe ViewModel shouldn't have any properties?


Solution

  • No, it isn't working correctly for view models... the framework is meant to support this.

    The good news is that there is a workaround. If you annotate the class to use the (more flexible) JAXB-style of view model, then it all works as expected.

    Here's an updated version of the class; look for annotations starting @Xml...:

    @XmlRootElement(name = "compareCustomers")
    @XmlType(
        propOrder = {
                "editableField"
        }
    )
    @XmlAccessorType(XmlAccessType.FIELD)
    public class HomePageViewModel {
    
        @XmlElement(required = true)
        @Setter @Getter
        @Property(editing = Editing.ENABLED)
        private String editableField;
    
        public TranslatableString title() {
            return TranslatableString.tr("{num} objects", "num", getObjects().size());
        }
    
        public List<SimpleObject> getObjects() {
            return simpleObjectRepository.listAll();
        }
    
        @XmlTransient
        @javax.inject.Inject
        SimpleObjectRepository simpleObjectRepository;
    }
    

    For more on JAXB view models, see the user guide.

    Meantime I've raised a JIRA ticket for the issue you've discovered,