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

Usuage of scope implicit objects in EL

 
Ashu Jain
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was reading scope implicit objects from HFSJ - got confused with this.
Please help.

HFSJ says that we use [] operator so that key that do not adhere to java naming rules can also work.

eg: request.setAttribute("foo.person",p); // p is instance of java bean.

I tried a small program wherein following worked

<%
foo.Employee p = new foo.Employee();
p.setName("Jain");
p.setEmpID(700);
request.setAttribute("foo.test",p);
%>
xxx is: ${requestScope["foo.test"].name}.

but there was an error in following.

<jsp:useBean id="foo.test" type="foo.Employee" class="foo.Employee" scope="request" >
<jsp:setProperty name="foo.test" property="name" value="JJain" />
<jsp:setProperty name="foo.test" property="empID" value="91" />
</jsp:useBean>

xxx is: ${requestScope["foo.test"].name}.

Can anyone please explain.
 
cesar valencia
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
foo.test is not a valid identifier for a property because of the little dot, but it is a valid identifier for a map key.

try something like this:

Asumming Employee has a map (Map<String, String> map) property.



edit:
that should work better

[ November 28, 2008: Message edited by: cesar valencia ]
[ November 28, 2008: Message edited by: cesar valencia ]
 
Matteo Palmieri
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, the foo.test is a valid identifier for a scope variable, but it is not a valid identifier for a scripting variable. When the <jsp:useBean> tag is used both are created and in this case, the second one fails
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic