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

旧城冷巷雨未停 提交于 2019-12-11 05:13:12

问题


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:

But it works fine for SimpleObject:

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


回答1:


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,



来源:https://stackoverflow.com/questions/44569302/apache-isis-propertyediting-editing-enabled-doesnt-work-for-viewmodels

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!