Working with dynamic variable names in EL

In EL, I want to access the value

${settings_123456.settingsMap[test].value} 

The problem is that settings_123456 is a variable. Therefore, I saved it in the variable ${setting} and tried ${setting.settingsMap[test].value} , but it does not work

Edit:

 Public class Setting { Map<String, myClass> settingsMap; } Public class myClass { private String myTest; } 

The model is installed with the Setting object, and I need to get the value of the myTest variable in my jsp using jstl. Also note that the key for settingsMap also dynamic, so you can see the test variable in the JSP code.

+4
source share
2 answers

You can access it by explicitly specifying the area map.

 ${requestScope[settings_123456].settingsMap[test].value} 

Use ${sessionScope} or ${applicationScope} instead in a session or application.

+6
source

You need to make the settingsMap property, i.e. declare a setter and getter for it:

 Public class Setting { Map<String, myClass> settingsMap; public Map<String, myClass> getSettingsMap() { return this.settingsMap; } public void setSettingsMap(Map<String, myClass> settingsMap) { this.settingsMap = settingsMap; } } 
0
source

Source: https://habr.com/ru/post/1403635/


All Articles