Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

trying to understand [] operator with paramValues

 
Sue Pillai
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a request with a single-valued parameter say username and a multi-valued parameter say companies:

To print the name and the first company using "." operator:

${param.name} prints Joe
${paramValues.companies[0]} prints Ford

Then, using the "[]" operator, it should be

${param["username"]} prints Joe
${paramvalues["companies[0]"]} prints nothing?

Where am I going wrong?
 
Bimal Patel
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sue,

Originally posted by Sue Pillai:

${paramvalues["companies[0]"]} prints nothing?


By this way, you're trying to get the parameter named "companies[0]" and not the 0th value of parameter values. I am not able to recall that how exactly you can get that.
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try

${param["companies"]}
 
Bimal Patel
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Vishnu,

That would return the 0th element of that array. Right? But what for any specific one? Any idea?
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

That would return the 0th element of that array. Right?


Yes you are correct.


But what for any specific one? Any idea?


I tried with other possibilities. Nothing is working.
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

${paramvalues["companies[0]"]} prints nothing?


Found the answer. Try with

${paramvalues["companies"][0]]}

I worked on it and got results.
 
Sue Pillai
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Vishnu. I had to remove the last ] from your answer, but I got the idea though.

${paramValues["companies"][0]} did work and picks companies at different indices.

I understand it now as:

paramValues["companies"] returns the reference to the String array and the [0] will get the element at the zeroeth position.

Correct me I am wrong.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic