VMware {code} Community
Sumit_Tyagi
Enthusiast
Enthusiast
Jump to solution

Finder properties having array as return type

Hi All,

Is there a way to deal with array return types of finders in vco?

If I give the property name in the bean-property attribute then it gives [Ljava.lang.String;@4981086 as value (as expected).

<property bean-property="testProp" display-name="Test Property" hidden="false" name="testProp" show-in-column="true" show-in-description="true"/>

But is there any way to specify bean-property attribute of finder tag so that we can wrap the property's value under a static utility method. May be something like below (I know the below line is not correct, but just a wild guess)

<property bean-property="StringUtils.joinArray(testProp)" display-name="Test Property" hidden="false" name="testProp" show-in-column="true" show-in-description="true"/>

Or any other way by which I can handle Array return types of properties.

Thank you for your assistance.

Best Regards,

Sumit Tyagi.

1 Solution

Accepted Solutions
Sumit_Tyagi
Enthusiast
Enthusiast
Jump to solution

Hi Sergio,

Got it now, we can specify any valid OGNL expression in property-accessor attribute of property tag. Read a bit about OGNL expressions and got it working.

The below property xml tag is working for me now.

<property property-accessor="arrayToString(testProp)" display-name="Test Property" hidden="false" name="testProp" show-in-column="true" show-in-description="true"/>


Best Regards,

Sumit Tyagi

View solution in original post

7 Replies
sanchezs
VMware Employee
VMware Employee
Jump to solution

Hi Sumit,

Have you tried specifying the bean-property in the same way you would specify an array in a method parameter for example? It should be something like:

<property bean-property="[testProp" display-name="Test Property" hidden="false" name="testProp" show-in-column="true" show-in-description="true"/> (yes, the name of the property prefixed with a '[')

Maybe that will be enough for simple types (strings, numbers and so).

I hope it helps.

Sergio

Reply
0 Kudos
Sumit_Tyagi
Enthusiast
Enthusiast
Jump to solution

Hi Sergio,

Yes, I tried that, but it failed with error "unable to find getter method/attribute for property: '[testProp'

Best Regards,

Sumit Tyagi

Reply
0 Kudos
sanchezs
VMware Employee
VMware Employee
Jump to solution

Hi Sumit,

Then I didn't recall it correctly 🙂 What is the return type of the method that returns that bean-property attribute? Is it String[] or List<String>? I've seen that in some plug-ins, with List<String> seemed to work. So with your original definition:

<property bean-property="testProp" display-name="Test Property" hidden="false" name="testProp" show-in-column="true" show-in-description="true"/>

If you have a method getTestProp returning String[] you can change it to List<String>, but if its a complex object then you can define a new method List<String> getTestPropDescriptions() in the class you use for the finder and update your property definition to:


<property bean-property="testPropDescriptions" display-name="Test Properties" hidden="false" name="testPropDescriptions" show-in-column="true" show-in-description="true"/>


Regards,


Sergio

Sumit_Tyagi
Enthusiast
Enthusiast
Jump to solution

Hi Sergio,

The property type is native array only (String[], byte[], short[] etc) not collections.

Ok I will give it a try as well, but in that case I will have to change my original java classes (which I do not want).

By the way, I was trying something else in this direction. I had seen vso.xml of vsphere plugin, and there we are able to call property of porperty if property is an object as shown below.

<property display-name="SDK Connection" name="vimHost" property-accessor="vimHost.name">

<property display-name="capacity (GB)" name="capacity" property-accessor="summary.capacity/(1073741824)">

So what I am trying is, I have made a function getArrayToString(Object arr) in the base java class (this function sniffs the 'arr' array type and call the corresponding StringUtils.joinArray function.)

Then I define my property as:-

<property property-accessor="arrayToString/(testProp)" display-name="Test Property" hidden="false" name="testProp" show-in-column="true" show-in-description="true"/>

But unfortunately this method also failed with error:- unable to invoke 'arrayToString/(testProp)''

Do you have any suggestions in this direction?

Best Regards,

Sumit Tyagi

Reply
0 Kudos
Sumit_Tyagi
Enthusiast
Enthusiast
Jump to solution

Hi Sergio,

Got it now, we can specify any valid OGNL expression in property-accessor attribute of property tag. Read a bit about OGNL expressions and got it working.

The below property xml tag is working for me now.

<property property-accessor="arrayToString(testProp)" display-name="Test Property" hidden="false" name="testProp" show-in-column="true" show-in-description="true"/>


Best Regards,

Sumit Tyagi

sanchezs
VMware Employee
VMware Employee
Jump to solution

Hi Sumit,

I was not sure if the OGNL expression in the property-accessor attribute was limited to resolve object properties (e.g. object.property1.property2...), basically by using the getters. Good to know that you try with other methods and it worked. Thank you for posting the solution back!

Regards,

Sergio

Reply
0 Kudos
Sumit_Tyagi
Enthusiast
Enthusiast
Jump to solution

Hi Sergio,

VMWare communities are one of the most active communities I have visited, and people engaged in these communities are really knowledgeable and helpful. Its my pleasure that my findings were helpful.

Best Regards,

Sumit Tyagi.