VMware {code} Community
alstraub
Contributor
Contributor

Passing browser data to DataProviderAdapter

I am trying to use browser local storage for some Plugin settings.

Is it possible to pass these settings to the DataProviderAdapter through a cookie or some other method?

I was able to get cookies working in the DataAccessController using the @CookieValue annotation but unsure if its possible to do the same with the DataProvider itself.

0 Kudos
4 Replies
laurentsd
VMware Employee
VMware Employee

If I understand correctly your question is about passing an extra parameter to the DataService when retrieving properties.  The solution is to include ParameterSpec[] to the PropertySpec created inside QueryUtil.java:

1) modify QueryUtil.getProperties to pass your extra parameter when called from your DataAccessController,

something like this:

  ...

    ParameterSpec paramSpec = new ParameterSpec();

     paramSpec.parameter = yourParamObject;   // <== can be a string or a java object.

     paramSpec.propertyName = yourPropName; //  <== this is the property that will include the extra param in your data provider

    ...

    PropertyValue[] pvs = QueryUtil.getProperties(_dataService, ref, props, paramSpec);

2) modify createPropertySpec() in QueryUtil.java to include that process that parameter

...

private static PropertySpec createPropertySpec(

         String[] properties, String targetType, ParameterSpec paramSpec) {

      PropertySpec propSpec = new PropertySpec();

      propSpec.type = targetType;

      propSpec.propertyNames = properties;

     propSpec.parameters = new ParameterSpec[] { paramSpec };  // must be an array

      return propSpec;

   }

3) extract the parameter from the PropertySpec in your data provider

0 Kudos
alstraub
Contributor
Contributor

Thanks Laurent, that will be useful when retrieving properties.

The issue I am facing is when using objectCollectionTemplate - I am not sure how to pass additional parameters.

0 Kudos
laurentsd
VMware Employee
VMware Employee

It is not possible to pass parameters to requested properties defined in plugin.xml, in a list column extension used by the ObjectCollectionTemplate for instance.

Those lists are created by the vSphere Client itself.

One work-around can be to cache the user setting in memory in your plugin java layer, using the userSession.clientId as the key.  And then retrieve it in your property provider.

You need to find a place in your plugin UI where you can make a service call to cache that data, for instance when the view is initialized.

Also, remember to use ClientSessionEndListener.sessionEnded to remove that cache when the user session ends.

0 Kudos
alstraub
Contributor
Contributor

Thanks for the confirmation; that was my fear but was holding out hope that there was some other option

I had considered some sort of caching but unfortunately that approach seems like an undesirable user experience.

0 Kudos