wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes trying to understand [] operator with paramValues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "trying to understand [] operator with paramValues" Watch "trying to understand [] operator with paramValues" New topic
Author

trying to understand [] operator with paramValues

Sue Pillai
Ranch Hand

Joined: Nov 04, 2004
Posts: 89
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?


Sue

SCJP 1.2
SCWCD 1.4
SCBCD 5.0
Bimal Patel
Ranch Hand

Joined: Aug 29, 2003
Posts: 130
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.


Work Hard, Expect The Worst...<br /> <br />Bimal R. Patel<br />(SCJP 1.2, SCWCD 1.4)
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
try

${param["companies"]}


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Bimal Patel
Ranch Hand

Joined: Aug 29, 2003
Posts: 130
Hey Vishnu,

That would return the 0th element of that array. Right? But what for any specific one? Any idea?
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026

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

Joined: Nov 15, 2004
Posts: 1026

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


Found the answer. Try with

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

I worked on it and got results.
Sue Pillai
Ranch Hand

Joined: Nov 04, 2004
Posts: 89
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: trying to understand [] operator with paramValues