XML DTOs are a kind of View Model, so maybe just using @ViewModel instead?
On Fri, Sep 23, 2016 at 10:55 PM, Simecsek Timothy <
[email protected]> wrote:
> Hi,
>
> I was able to find a solution that I want to share:
>
> In the domain object I added this method:
> @MemberOrder(sequence = "2.0")
> @PropertyLayout(hidden = Where.ALL_TABLES)
> @CollectionLayout(named = "request headers", render =
> RenderType.EAGERLY)
> @XmlElementWrapper
> @NotPersistent
> public ArrayList<StringMapElementVo> getStringListElement() {
> final ArrayList<StringMapElementVo> stringMapVo =
> Lists.newArrayList();
> for (String key : this.getRequestHeaders().keySet()) {
> final StringMapElementVo stringMapElement = new
> StringMapElementVo();
> stringMapElement.setKey(key);
> stringMapElement.setValue(this.getRequestHeaders().get(key));
> stringMapVo.add(stringMapElement);
> }
> return stringMapVo;
> }
>
> And set the persisted field to not show:
> private Map<String, String> requestHeaders = Maps.newHashMap();
>
> @PropertyLayout(hidden = Where.EVERYWHERE)
> @Persistent(defaultFetchGroup = "true")
> public Map<String, String> getRequestHeaders() {
> return requestHeaders;
> }
>
> And here the JAXB annotated DTO see [1] :
> @XmlRootElement(name = "KeyValueElement")
> @DomainObject(editing = Editing.DISABLED)
> public class StringMapElementVo {
>
> public StringMapElementVo() {
> }
>
> //region > key (property)
> private String key;
>
> public String getKey() {
> return key;
> }
>
> public void setKey(final String key) {
> this.key = key;
> }
> //endregion
>
> //region > value (property)
> private String value;
>
> public String getValue() {
> return value;
> }
>
> public void setValue(final String value) {
> this.value = value;
> }
> //endregion
> }
>
> I used a very similar approach for a List<String> property also. This way
> it displays in the UI like any other collection of persistent Domain
> Objects. If you need this to act as an object you can add another DTO
> around it.
>
> Regards Timothy
>
> [1] https://isis.apache.org/guides/ugbtb.html#2.3.-jaxb-annotated-dtos
>
> -----Ursprüngliche Nachricht-----
> Von: Simecsek Timothy
> Gesendet: Donnerstag, 22. September 2016 10:58
> An: [email protected]
> Betreff: Display HashMap in UI
>
> Hi,
>
> I'm using a Map<String, String> in one of our DomainObjects which is
> stored in one column of this class.
> This is the definition:
> //region > requestHeaders (collection)
> private Map<String, String> requestHeaders = Maps.newHashMap();
>
> @MemberOrder(sequence = "2.0")
> @CollectionLayout(named = "request headers", render = RenderType.EAGERLY)
> @Persistent(defaultFetchGroup = "true") public Map<String, String>
> getRequestHeaders() {
> return requestHeaders;
> }
>
> private void setRequestHeaders(final Map<String, String> requestHeaders) {
> this.requestHeaders = requestHeaders; } //endregion
>
> Now I want to display the content of the Map in the UI. Currently it shows
> me:
> ...
> Request Headers Untitled Hash Map
> ...
>
> Where "Untitled Hash Map" is a clickable object but when I click on it I'm
> forwarded to the start page.
>
> Is there any possibility to get this working with HashMap?
>
> Thanks Timothy
>
>
> ______________________________________________________________________
> Disclaimer: This email and any attachments are sent in strictest
> confidence for the sole use of the addressee and may contain legally
> privileged, confidential, and proprietary data. If you are not the intended
> recipient, please advise the sender by replying promptly to this email and
> then delete and destroy this email and any attachments without any further
> use, copying or forwarding.
>
> ______________________________________________________________________
> Disclaimer: This email and any attachments are sent in strictest confidence
> for the sole use of the addressee and may contain legally privileged,
> confidential, and proprietary data. If you are not the intended recipient,
> please advise the sender by replying promptly to this email and then delete
> and destroy this email and any attachments without any further use, copying
> or forwarding.
>