• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Populating a dropdown box from data in the database

 
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a toy program for school.

I'm trying to generate a dropdown box on a page used to update an object. I would like to select the object in the top from the list of "all objects", then use the data in the object to populate the editable fields down bottom. The bottom area is a form which posts an update to the object.

I am having a hard time getting the data from the service layer to the jsp. I tried populating a static list in my domain object, but the tomcat log showed that it was calling the method recursively and blowing out my data connections. So I moved the population of the list to the controller and called it from the init method in the servlet. Probably not ideal, also doesn't work -- I'm getting "property not found on object" Jasper exceptions.

I'm sure there's a pattern for this, but I have tried searching google and I only come up with folks who populate after the page has loaded. I clearly need the list populated as the page is loading.

Are there pointers on this somewhere? Am I missing something obvious?

 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using JavaScript on change event? You can set up a call back so that when the drop down choice is selected, an event automatically fires that's loads the data from the data layer and populates your fields as needed. You often need a separate call back servlet to load the data from.
 
Janeice DelVecchio
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is before that.

I can't even get the data in the dropdown to show up. The list is null and I get a weird blank dropdown with nothing in it.

I wrote a fancy JavaScript function to get called when onChange occurs, but I can't change the selection because there's nothing to select.
 
Scott Selikoff
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post the snippet where you are creating the drop down?
 
Janeice DelVecchio
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As you can see, this program is for my nephew to keep track of his Skylanders Adventure characters. :)




And here's the error:

exception

org.apache.jasper.JasperException: org.apache.jasper.el.JspPropertyNotFoundException: /update.jsp(29,4) '${characterBean.allSkylanders}' Property 'allSkylanders' not found on type model.domain.SkylanderBean
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
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:728)


root cause

org.apache.jasper.el.JspPropertyNotFoundException: /update.jsp(29,4) '${characterBean.allSkylanders}' Property 'allSkylanders' not found on type model.domain.SkylanderBean
org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:109)
org.apache.jsp.update_jsp._jspx_meth_c_005fforEach_005f0(update_jsp.java:141)
org.apache.jsp.update_jsp._jspService(update_jsp.java:103)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
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:728)

 
Janeice DelVecchio
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I remove the JS function and the form, I get this:



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

13: <body>
14:
15: <select name="skylander" >
16: <c:forEach items="${characterBean.allSkylanders}" var="character">
17: <option value="${character}"><c:out value="${character.name}" /></option>
18: </c:forEach>
19: </select>


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:728)


root cause

org.apache.jasper.el.JspPropertyNotFoundException: /update.jsp(16,4) '${characterBean.allSkylanders}' Property 'allSkylanders' not found on type model.domain.SkylanderBean
org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:109)
org.apache.jsp.update_jsp._jspx_meth_c_005fforEach_005f0(update_jsp.java:119)
org.apache.jsp.update_jsp._jspService(update_jsp.java:90)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
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:728)

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Show us the SkylanderBean -- it's likely that the property accessor for allSkylanders is not named correctly (or isn't public?).
 
Janeice DelVecchio
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the bean....


I populate it with a service that uses Hibernate. Other pieces that use hibernate/this bean work and I can see them from the view correctly.

here's the query:

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need an accessor for the allSkylanders property. Making the variable public is not allowed by the bean standard and the EL won't see it.
 
Janeice DelVecchio
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Scott told me to try it without the accessor.

I have the same error with or without a public getter.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add the accessor. It will not work without it. Make sure that is is named getAllSkylanders and that it is public and not static.
 
Janeice DelVecchio
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excellent!!! The page stopped exploding! :) :) :)

But my dropdown is still tiny and empty. :(
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most likely cause is that the list is empty. You can log it to see what it contains, or even use the empty operator on the page as a quick test:
 
Janeice DelVecchio
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have some system out statements inside my hibernate service and it doesn't seem to be getting there.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So the problem lies deeper!

P.S. Highly recommend Log4J in place of sys out.

/off-to-bed-for-bear
 
Janeice DelVecchio
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Log4J is outside the scope of this class. :D

Night Bear/Scott. Thanks for your help.
 
reply
    Bookmark Topic Watch Topic
  • New Topic