0

I was reading some code and I found the next EL expression inside a JSF file:

  ${text['somefield']}

How is it work?.

Since I don't have access to the whole code, I can check what it is. Is it "text" a managed bean?.

Because I could understand the next code:

  ${someBean.text['somefield']}

(accessing a field array inside a bean but it's not the case.

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
magallanes
  • 6,583
  • 4
  • 54
  • 55
  • It is most likely a Map. – Jorge Campos May 05 '18 at 11:13
  • It can also be a field defined in the faces-context.xml , a resource bundle. – Jorge Campos May 05 '18 at 11:16
  • A map in any scope indeed (e.g. via CDI `@Producer`) or even something that is resolved via a custom EL resolver. – Kukeltje May 05 '18 at 11:54
  • 1
    Possible duplicate of [How JSF el expression works and when a JSF variable resolver will be involved while evaluating any JSF exprestion?](https://stackoverflow.com/questions/33576739/how-jsf-el-expression-works-and-when-a-jsf-variable-resolver-will-be-involved-wh) – Kukeltje May 05 '18 at 12:05

1 Answers1

0

text can be a managed bean, a CDI dependency (these are the 2 most likely)

text['somefield'] is reading somefield field of text object. text is likely to be a map, but it could be a normal bean too. It's equivalent to text.somefield

In the documentation, you can also find similar exampes:

${customer.address["street"]}

Which is similar to:

${customer.address.street}
ernest_k
  • 44,416
  • 5
  • 53
  • 99
  • It can be way more... Just a HashMap that is somewhere put in the request scope (or any scope for that matter where EL in the current context has access to). It can be a resourcebundle... Or even something that can be resolved via a custom resolver... – Kukeltje May 05 '18 at 11:52
  • @Kukeltje Yeah, right. I just wanted to mention the most likely ones, given the custom name `text` (at least for me, it's not recognizable as a built-in object/bean). You're welcome to edit this answer or post a different one. The more details, the better, I suppose... – ernest_k May 05 '18 at 11:55
  • Sort of... Most likely one for me is a resourcebundle... But if you know upfront that your answer is not extensive, please state so. Otherwise newcomers might be confused... – Kukeltje May 05 '18 at 12:04
  • And there is a duplicate ;-) – Kukeltje May 05 '18 at 12:05