• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL Functions and Parameters

 
Mike C Bennett
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

I have been doing some EL examples whilst studying for my SCWCD exam and was wondering if anyone knows if it is possible to pass an expression as a parameter to an EL function?

For example, I have a function called bark(String breed). The breed is available as a property of a bean stored as a request parameter and I want to be able to pass this to the function:

${mine:bark(${person.dog.breed})}

If I leave the function like this, it fails as it is expecting a string (and the evaluated result is not a string). If I put quotes around the expression:

${mine:bark("${person.dog.breed}")}

it does not get evaluated.

It works if I do ${mine:bark("Labrador")}

Does anyone know if it is possible to do this? I was just wondering!! I even tried replacing the EL expression with a standard <%= %> expression in quotes and that didn't work either!!

Cheers,



Mike
 
Rodrigo W Bonatto
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Yes, you can pass an expression as a parameter to an EL function using EL implicit objects:

To get a parameter from request
${mine:bark(param.paramName)}

In your example you can try this:
${mine:bark(requestScope["person"].dog.breed)}

Regards,

Rodrigo
 
Mike C Bennett
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rodrigo,

I have just tried that and got exactly the result I was hoping for!!
 
Mike C Bennett
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've just realised the mistake I was making was to wrap the argument expression in ${}. If I had just called ${mine:bark(person.dog.breed)} instead of ${mine:bark(${person.dog.breed})} it would have worked too!!

Thanks again for your help, as seeing the example made me realise my mistake!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic