• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

trying to understand [] operator with paramValues

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try

${param["companies"]}
 
Bimal Patel
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
LOOK! OVER THERE! (yoink) your tiny ad is now my tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic