Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

scope implicit objects in EL?

 
Jingh Yi
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following EL implicit object:
- pageScope
- requestScope
- sessionScope
- applicationScope

why do we need them? they can only be used to retrieve the attributes inside that scope, right? But we can directly access the attributes in those scopes by referencing the attribute names set in those scopes???

Thanks,
Jenny
 
bengt hammarlund
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
supose you want to guarantee that an attribute comes from the request, even if the page scope have an attribute with the same name... you need requestScope for that.

They are meant to give the developer control from what scope he/she wants to get the attribute value from.

If you use only the name of the attribute, it will be searched in all scopes (from page down to application - correct me if I'm wrong!) and the value returned whould be of the first with the name you gave.

Hope that clarifies.
 
Mat Williams
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

There is also the issue that I think HFSJ mentioned where you may have a variable that will not work in an EL expression using dot notation (because the variable name is not valid to use in dot notation), but you can access it using the [""] notation. To achieve this you need the scope variable outside the [""]. I can't at the moment think of an example to show this but I am sure I came across one probably in HFSJ.

Mat
 
Jingh Yi
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bengt,

It's a valid point. Thanks.

Mat,

Not sure what you are talking about. Sorry.
 
Sergey Tyulkin
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a dot in the attribute name, you will not able to reference it without scope implcit object.
For example
If you have such statement:
request.setAttribute("my.attribute", "Try this");
then you must use something like
${requestScope["my.attribute"]} to get the attribute's value
 
Jingh Yi
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bengt and Mat,

Thanks for reply.

Mat, I think I got your point. for example, if there is an attribute like 'person-name', then we have to use xxx["person-name"] instead of using the dot operator or the attribute name itself.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic