• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set values from script element as attribute's using EL or JSTL ????

 
Reshma Shanbhag
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,



The above code fails with a NullPointerException, when the doTag() method of the tag handler class executes as the value of attribute movieList is NULL. Any Idea why the the c:set tag finds the movieLst as NULL value???

Replace the c:set with the scripting to set the page scoped attriute works fine.

I am newbie at these, any help is greatly appriciated.

Thanks and Regards,
Reshma
[ May 18, 2006: Message edited by: Reshma Pai ]
 
Reshma Shanbhag
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i guess i got it now,

${movieLst} tries to see through the scopes (page, request ..) and finds there is no Attribute with this name .. hence returns NULL.

movieLst variable is visible within the service() and is not set to any scopce .. hence the NullPointer.


Now my next question is, is there a way to set movieLst to an attribute without using
pageContext.setAttribute("movieAttrList",movieLst);
 
Reshma Shanbhag
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no one to help me with this !!! ???

I am looking for your help ranchers ....
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You only posted this a day ago - please allow both us (and more importantly yourself) to get around to looking at, and replying to, your question before reposting...

Now my next question is, is there a way to set movieLst to an attribute without using...

No; all page-scoped attributes are contained in the PageContext (or JspContext) instance. The only way to set the attributes programmatically through scriptlet code is using pageContext.setAttribute(...).
 
Rodrigo Alvarez
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm not sure, but I think that when you declare a servlet variable, it's automatically available in the pageScope. So you can try this:



then fill it as you do (whithout re-declaring it) and see if it is available throught {movieLst}.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rodrigo Alvarez:
I'm not sure, but I think that when you declare a servlet variable, it's automatically available in the pageScope.


Nope. Charles is right. It would have to be set to the page context explicitly.
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you must add it manually using the JspContext (or PageContext) instance, or if you're instantiating a new bean you can in fact use <jsp:useBean />.
 
Reshma Shanbhag
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help Charles.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Reshma,

In addition to Marc and Charles.

By some way you have to set the attribute in the pageContext using Standard or custom action. In your example you can do small changes to set the attribute the the pageContext. Instead of using the EL expression in the c:set you can use the scripting expression to set the page scoped attribute movieAttrList.



This will set the page scoped variable using scripting expression to the scripting variable arry. If I am not missing something, this should work correctly.

Thanks
 
Reshma Shanbhag
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya Narendra the scripting option works ..

Thanks,
Reshma
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic