Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

JSF and ResultSets

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am attempting to use a ResultSetDataModel and a ResultSet together to bind a ResultSet to a HtmlDataTable.
my code looks somehting like this

#.java#

getData(){
if(rsdm == null){
ResultSet rs = null;
rsdm = new ResultSetDataModel();
rs = stmt.executeQuery();
rsdm.setWrappedData(rs);
}
return rsdm;
}


#.jsp#

<h ataTable value="#{backingBean.data}" var="row">
<h:column>
<f:facet name="header">
<h utputText value="Name"/>
</f:facet>
<h utputText value="#{row.name}"/>
</h:column>

This gives me an exception.

Removing the <h utputText value="#{row.name}"/> gives the desired result in that it prints out Name the appropriate number of times. This leads me to believe that the data is being looped over. However I cannot figure out the appropriate access method for the ResultSetDataModel. If I used an ArrayListDataModel I could access the attributes of the enclosed class through the "." operator. however since this is a resultSet and all of its members are accessed through rs.getString("Name") reflection fails. Anyone have any idea or had experience with this method of data access?
Thank you
Michael
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Frameworks forum.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Care to share what the Exception was? That's usually helpful. Kind of they are there, you know.

My first guess from the info provided is that you don't have a column named "name" in your ResultSet. But without the Exception it is just a guessing game from there.
 
Michael Rasmussen
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get a
javax.faces.el.EvaluationException: Error getting property 'wineModel' from a bean of type winetracker.handlers.WineHandler:java.lang.NullPointerException

in my backing bean I have a
getWineModel() method that returns a DataModel

When I use a ListDataModel instead of a ResultSetDataModel and I change the contents of the model from a resultSet to a list of objects this works fine. So the exception provided by faces is IMO misleading. What is really going on is that it cannot find a method in the underlying object called getWineName. Which makes sense since there is no underlying object with a method called getWineName, rather there is a resultSet with an underlying method called getString("wineName"). What I am looking for is how to get the el to recognize that I want it to look at it as a resultset instead of a class. If this can't be done then what is the prupose of the ResultSetDataModel?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Michael Rasmussen:
I get a
javax.faces.el.EvaluationException: Error getting property 'wineModel' from a bean of type winetracker.handlers.WineHandler:java.lang.NullPointerException

in my backing bean I have a
getWineModel() method that returns a DataModel

When I use a ListDataModel instead of a ResultSetDataModel and I change the contents of the model from a resultSet to a list of objects this works fine. So the exception provided by faces is IMO misleading. What is really going on is that it cannot find a method in the underlying object called getWineName. Which makes sense since there is no underlying object with a method called getWineName, rather there is a resultSet with an underlying method called getString("wineName"). What I am looking for is how to get the el to recognize that I want it to look at it as a resultset instead of a class. If this can't be done then what is the prupose of the ResultSetDataModel?



So what you are telling me is that the code you posted is made up. Ok. When you create a List using a DataListModel then EL will look for the getWineName method in the object in the list. You are using a ResultSet from a Database. So instead of getWineName or BackBean.wineName, you need to request the column name. What is the name of the column that contains the wine name?

In the future, it is best to post the actual code you are having a problem with. Especially when dealing with exceptions. Also, when posting JSP tags, you'll want to check the checkbox that says "Disable smilies" so that things like



don't get rendered with smilies where the are. And using [ code ] tags makes your code easier to read.
[ November 10, 2004: Message edited by: Gregg Bolinger ]
 
Michael Rasmussen
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, thank you for tolerating my "newbism". I will heed your advice. So I tried using the column name which is wineName and accessing it through
<code>
<h:dataTable value="#{wineBackingBean.wineModel}" var="wine"
styleClass="winetable" rowClasses="oddRow, evenRow"
columnClasses="left, center, center, right" >
<h:column>
<f:facet name="header">
<h:outputText value="Wine"/>
</f:facet>
<h:commandLink action="#{wineBackingBean.showWine}">
<h:outputText value="#{wine.wineName}"/>
</h:commandLink>
</h:column>


</code>

my backing code is

<code>

public DataModel getWineModel(){
if(ldm == null){
ldm = new ResultSetDataModel();
ResultSet rs = wineDAO.getWines();
ldm.setWrappedData(rs);
}
return ldm;
}

</code>

And I have a column named wineName

The exception I get is

javax.servlet.ServletException: javax.servlet.jsp.JspException: javax.faces.el.EvaluationException: Error getting property 'wineModel' from bean of type winetracker.handlers.WineHandler: java.lang.NullPointerException
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:821)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.wines_jsp._jspService(wines_jsp.java:86)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:147)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:670)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:637)
org.apache.jsp.index_jsp._jspService(index_jsp.java:45)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


Sorry I didn't actually give all this before, I didn't have Internet access this morning on my laptop.
Thanks,
Michael
 
A timing clock, fuse wire, high explosives and a tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic