Question

I have a problem in populating a grid using an EnumMap as bind:

<grid sizedByContent="true" span="true" model="@bind(vm.pendingRequests[RequestType.RETURN])" 
emptyMessage="Nessuna richiesta trovata" height="100%" width="100%">

In the view model there is the declaration of the map:

private Map<RequestType, List<PendingRequest>> pendingRequests;

Where RequestType is an enum:

public enum RequestType {
    EXIT("exit"),
    RETURN("return"),
    PARKING("park");

    private final String description;

    private RequestType(String description) {
        this.description = description;
    }

    public String getDescription() {
        return description;
    }

    public static RequestType getEnum(String value) {
        if (value == null) {
            throw new IllegalArgumentException();
        }
        for (RequestType v : values()) {
            if (value.equalsIgnoreCase(v.getDescription())) {
                return v;
            }
        }
        throw new IllegalArgumentException();
    }
}

Do you know where I'm wrong in populating the grid using an EnumMap and bind?

Thank you very much!

Was it helpful?

Solution 2

Following the suggestion of @bidifx I changed the zul in this way:

<grid sizedByContent="true" span="true" model="@load(vm.getPendingRequests('RETURN'))" 
       emptyMessage="Nessuna richiesta trovata" height="100%" width="100%">

And in the view model I created a method that returned directly the list to the zul:

public List<PendingRequest> getPendingRequests(String stype) {
        RequestType type = RequestType.valueOf(stype);
        return pendingRequests.get(type);
    }

This worked for me. Thanks to all!

OTHER TIPS

So here we go:

You can not directly access static class members. This also applies to enum which is in some way the same. So you have to use this little workaround...

  1. create a getter for your enum item:

    public EnumType getTypeItem() {
      return EnumType.Item;
    }
    
  2. use this getter in your ZUL

    <label value="@load(vm.typeItem)">
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top