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

JSTL c:set doubt

 
gayatri ganesh
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In HFSJ book page 447, they have some key points for <c:set> . In the last comment they say

"If the targetexpression is a bean,but the bean does not have a property that matches "property" the container throws an exception. But be careful because the EL expression by itself will NOT cuase an exception if the preoperty does not exist. So even though ${fooBean.notAProperty} won't cause an exception by itself(it justt returns null),if that same notAProperty is the value of a "target" attribute the Container throws an exception."


According to this line, if I have something like ${person.empID} and empID is not a property of that bean,I should not get an exception.

But I get the follwing exception when I print ${person.empID}

javax.servlet.ServletException: Unable to find a value for "empID" in object of class "com.example.Person" using operator "."org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.customtag_jsp._jspService(org.apache.jsp.customtag_jsp:150)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.example.ListenerTester.doGet(ListenerTester.java:64)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Please clarify

Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The spec says that if the property is not a readable property of the bean, then it must be an error. I think that the statement at page 447 is not correct.
 
Deepinder S Narang
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What he is trying to say over here is that if the TARGET is set to a bean by the expression and the property mentioned in c:set does not exist in the bean then an exception will be caused but EL will simply return null and the result printed will be blank value. So no exception thrown will be shown on the jsp page.

But in case we are setting the TARGET using the expression and that property, which was supposed to set the value of the TARGET does not exist then it will generate an exception.

Correct me if i am wrong friend .........
 
Muralidhar Adhikarla
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , The JSP specification says that if the property specified is not their in the java bean then it will give an error.

So ${person.empID} will give an error if empID is not the property of person bean.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic