• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on default value in the c:out tag

 
Anupama Ponnapalli
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is an example that I put together to demonstrate the use of "default" attribute of c ut tag. Could someone kindly help me understand why it is not working.

I have a very simple JSP that looks like this:



There is no error, but the default value is not displayed. If this means that the userName EL variable is not null, how does one run such a test?

My application server is tomcat. I copied the standard.jar and jstl.jar in the jsp-examples/web-inf/lib folder into the web-inf/lib folder in my own web-app. I did not make any additions for the core taglib in web.xml.

Thanks,
Anu

[ January 31, 2007: Message edited by: Anupama Ponnapalli ]
[ January 31, 2007: Message edited by: Anupama Ponnapalli ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simply remove the c:set tag.
 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satou
Can you please explain it?

Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This syntax of c:set uses the tag's body as the value.
JSTL spec:
If the body content is used to set the value of an attribute, then an empty body content sets the attribute value to an empty string.

Here, the body being empty, an empty string is set into userName. Therefore, it exists, and the default value of c ut will not be used.

The userName will not be put into scope if its value is null.
For example :
<c:set var="userName" scope="page" value="${null}" />
[ January 31, 2007: Message edited by: Satou kurinosuke ]
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the body content is used to set the value of an attribute, then an empty body content sets the attribute value to an empty string.


wow man,,,

awesome !
 
Anupama Ponnapalli
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response, Satou!

To add to the question, why do I get a null pointer exception when I add this to the jsp:



If I remove the body content, it works



- Anu
[ February 01, 2007: Message edited by: Anupama Ponnapalli ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It may depend on where you are using "userLocation".
It will be difficult to say without seeing the full stack trace.
 
Anupama Ponnapalli
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP page is



As you can see, I am not attempting to retrieve the value assigned to userName at all!



In the generated Java class,


[ February 02, 2007: Message edited by: Anupama Ponnapalli ]
[ February 02, 2007: Message edited by: Anupama Ponnapalli ]
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same code working fine for me, could be someother problem not sure
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic