0 Replies Latest reply: Aug 11, 2013 1:59 PM by user7387906 RSS

    jsp:useBean gens different code causing InstantiationException

    user7387906

      Hello All,

         I am using a bean component that has a no-arg constructor and is tagged as serializable. The bean only contains getters and setters for strings so all fields are serializable. I have placed a jsp:useBean tag in the primary page and am getting a java.lang.InstantiationException when the page loads. I messed around extensively with the configuration of the page, the bean, etc. and had no luck. I finally created a new page and the bean worked fine. I placed the bean in another page and it worked fine there also. I looked at the page creation and all are jsp's (not jspx, jspf, etc.) and they are all jsp's and created in Netbeans 7.3 so I believe they are created to JSP spec 1.2. For some reason though, one page generates the correct creation code and the other does not, causing the exception. Here is the JSP creation code and the resultant, generated jsp servlet for each. Any ideas are helpful.

       

      jsp:  <jsp:useBean id="buttonLabels" scope="page" class="com.blackwidow.web.solutions.libs.ButtonLabels" /><br/>

       

      gen:  com.blackwidow.web.solutions.libs.ButtonLabels buttonLabels = null;

            synchronized (_jspx_page_context) {

              buttonLabels = (com.blackwidow.web.solutions.libs.ButtonLabels) _jspx_page_context.getAttribute("buttonLabels", PageContext.PAGE_SCOPE);

              if (buttonLabels == null){

                buttonLabels = new com.blackwidow.web.solutions.libs.ButtonLabels();

                _jspx_page_context.setAttribute("buttonLabels", buttonLabels, PageContext.PAGE_SCOPE);

              }

            }

       

      ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

      jsp: <jsp:useBean type="com.blackwidow.web.solutions.libs.ButtonLabels"

                        scope="page"

                        id="buttonLabels"/>

       

      gen: com.blackwidow.web.solutions.libs.ButtonLabels buttonLabels = null;

            buttonLabels = (com.blackwidow.web.solutions.libs.ButtonLabels) _jspx_page_context.getAttribute("buttonLabels", PageContext.PAGE_SCOPE);

            if (buttonLabels == null){

              throw new java.lang.InstantiationException("bean buttonLabels not found within scope");

            }