Attributes naming convention resulting in long EL expressions in JSP Page
Asked Answered
P

1

6

I'm writing lot of JSP pages for different views. Those JSP retrieve request scope attributes which have very long names to prevent overlapping. An example is:

request.getAttribute("domain1.subdomain1.subdomain11.subdomain111.attributeName");

Equivalent in EL would be:

${requestScope['domain1.subdomain1.subdomain11.subdomain111.attributeName']}

Sometimes, my EL expressions are very long (for example when I use 3 different JavaBeans to create an HTML tag or call javascript function).

My question is about whether or not the solution I found is a good programming solution. Given the fact that each view has it's own page scope, at the beginning of my JSP, I want to put

<c:set var="attributeName" scope="page" value="${requestScope['domain1.subdomain1.subdomain11.subdomain111.attributeName']}"

And then in my EL expressions, I will use

${pageScope["attributeName"]}

Isn't this going to create confusion about the actual scope of the attribute when reading the JSP code?

Profitsharing answered 3/6, 2013 at 14:5 Comment(4)
Even if you are going to implement this, this will be a violation of the law of demeter. Isn't it possible to develop jsp components for subdomain111 and plug those components together for a subdomain11 jsp component and so on?Rame
That would be a very good solution, but the attributes naming convention is out of my reach. The request goes through many steps before reaching the JSP and there are even Filters that process the request after the JSP using some attributes. I can not change the attributes naming in the request. I do not even have my hand on various controllers that set some attributesProfitsharing
It should be ${pageScope[attributeName]} (without the quotes).Hamlet
I'm not sure because using this syntax, I think that the EL would search for a variable attributeName and use it's value to search in the pageScope which is actually not a String.Profitsharing
H
0

This seems as if you are creating an alias for long variable name; which is ok.

Herod answered 8/6, 2015 at 4:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.