*
The moose likes JSP and the fly likes Java Simple Tag Handler Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Java Simple Tag Handler" Watch "Java Simple Tag Handler" New topic
Author

Java Simple Tag Handler

Mohit Chauhan
Greenhorn

Joined: Dec 23, 2012
Posts: 5
Hi , My code is as below ....
with following jsp's,classes and tld files :

Getting exception for its execution:



form.jsp:






web.xml:





SimpleServlet.java : [Servlet class]










SimpleTagDynamic.java : [TagHandler Class]









simple.tld:










I am getting here exception as :

type Exception report

message An exception occurred processing JSP page /form.jsp at line 7

description The server encountered an internal error that prevented it from fulfilling this request.

exception:

org.apache.jasper.JasperException: An exception occurred processing JSP page /form.jsp at line 7

4: <form method="POST" action="Dynamic.do">
5: <p>Select beer characteristics
6: Color:
7: <formTags:select name='Color' size='1' optionsList='${applicationScope.colorList}' />
8: <br>
9: </form>
10: </body>


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

root cause

java.lang.NullPointerException
foo.SimpleTagDynamic.doTag(SimpleTagDynamic.java:60)
org.apache.jsp.form_jsp._jspx_meth_formTags_005fselect_005f0(form_jsp.java:107)
org.apache.jsp.form_jsp._jspService(form_jsp.java:73)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)




Please help ...
Marc Pfaller
Greenhorn

Joined: Feb 28, 2013
Posts: 3
I hope it's not too late to help you.

In your SimpleTagDynamic Class you construct your html select Tag.

1. In Line 48 you open the select Tag, but it is never closed. You should close it with /> or </select>
2. In Line 48 there has to be a whitespace after the <select otherwise the html code would look like <selectname='myAttributesName'

Before: out.println("<select");
After: out.println("<select ");

And in Line 68 there has to be a whitespace too after the second %s otherwise your html code will stick together like in the example above.

Before: private static final String ATTR_TEMPLATE= "%s='%s'";
After: private static final String ATTR_TEMPLATE= "%s='%s' ";

In your SimpleServlet you fill your colorList and set it as an Context Attribute, but the Servlet is never invoked (Your html form has the action Dynamic.do), therefore the attribute is never set and when you try to get the optionsList in the SimpleTagDynamicClass you will get the NullPointerException.

Good Luck :)
Mohit Chauhan
Greenhorn

Joined: Dec 23, 2012
Posts: 5
Thanks Mark :)
 
jQuery in Action, 2nd edition
 
subject: Java Simple Tag Handler
 
Similar Threads
setDynamicAttribute not being invoked
how to pass Parameter in custom tag
Using EL to generate attribute/value pairs inside of an XHTML element
unable to access the attribute in any of the container scope
Doubt in JSP Custom tags (Simple Tag) in Dynamic Drop Down