Search code examples
sessionjsf-2el

Get session attribute having attribute name in a constants file


I want to get a session attribute from xhtml file. I know that if you put the attribute name like this #{sessionAttributeName.field} it works but my problem comes when I try to get the attribute name from a constants file.

I've imported the constants file with <p:importConstants type="Constants" var="constants"/>

I've tried get the attribute using #{constants.constantAttributeName.field} (constantAttributeName value is sessionAttributeName) but, how I expected, it doesn't work.

Is it possible get the session attribute using the constant with another method or another way to do this?

I could put directly the attribute name in all xhtml files, but if it changes, I should change all files.

Do you have idea?


Solution

  • I've solved it. I've used #{sessionScope[constants.constantAttributeName].field} and now it's working.