Topic
The topic of this question is: tracking the content of an array in a session bean debug sessionbean1.java
Hello and Thank you in advance for any assistance.
Purpose:
The purpose of this code is to try to find the best way to get a list of what is in the Content[] in the session bean.
Question:
My question concerning this code is the table headers are reflecting the binding for the Sessionbean1.content but the data does not display
Functionality:Based on visual web javaserverfaces app tutorial at :
http://www.netbeans.org/kb/60/web/web-jpa.html
The actual functionality of this code is :
I have two apps one containing the main and an entity class and controller class
The web app has the app.jar files so they are linked.
The MLPController loads the data into Content[] content the JSP is bound to the Sessionbean1.content,the Sessionbean init() and calls the updateContent() to fill the Content[] content I have no Idea what is actually in the content array.
errors:
The errors related to this code there is not data displaying in deployed visual web javaserverfaces table.
Description
Code description the persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="MLPAppPU" transaction-type="RESOURCE_LOCAL">
<provider>oracle.toplink.essentials.PersistenceProvider</provider>
<class>mlpapp.Content</class>
<properties>
<property name="toplink.jdbc.user" value="root"/>
<property name="toplink.jdbc.password" value="ceyezuma"/>
<property name="toplink.jdbc.url" value="jdbc:mysql://localhost:3306/splashbookdb"/>
<property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
</properties>
</persistence-unit>
</persistence>
Description
Code description: table to display
CREATE TABLE content(
id INT(5) NOT NULL AUTO_INCREMENT PRIMARY KEY,
publisher_code CHAR(2),
book_isbn char(20),
book_title char(100),
artist char(150),
song char(150),
page_num INT(4)
);
INSERT INTO content (publisher_code,book_isbn,book_title,artist,song,page_num) VALUES
('HL','0-634-05315-9','Guitar Tab White Pages Vol 2','Bryan adams','Its Only Love',371);
Description
Code description:the Entity class
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mlpapp;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
/**
*
* @author depot
*/
@Entity
@Table(name = "content")
@NamedQueries({@NamedQuery(name = "content.findAll", query = "SELECT c FROM content c"), @NamedQuery(name = "content.findById", query = "SELECT c FROM content c WHERE c.id = :id"), @NamedQuery(name = "content.findByPublisherCode", query = "SELECT c FROM content c WHERE c.publisherCode = :publisherCode"), @NamedQuery(name = "content.findByBookIsbn", query = "SELECT c FROM content c WHERE c.bookIsbn = :bookIsbn"), @NamedQuery(name = "content.findByBookTitle", query = "SELECT c FROM content c WHERE c.bookTitle = :bookTitle"), @NamedQuery(name = "content.findByArtist", query = "SELECT c FROM content c WHERE c.artist = :artist"), @NamedQuery(name = "content.findBySong", query = "SELECT c FROM content c WHERE c.song = :song"), @NamedQuery(name = "content.findByPageNum", query = "SELECT c FROM content c WHERE c.pageNum = :pageNum")})
public class Content implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Column(name = "publisher_code")
private String publisherCode;
@Column(name = "book_isbn")
private String bookIsbn;
@Column(name = "book_title")
private String bookTitle;
@Column(name = "artist")
private String artist;
@Column(name = "song")
private String song;
@Column(name = "page_num")
private Integer pageNum;
public Content() {
}
public Content(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getPublisherCode() {
return publisherCode;
}
public void setPublisherCode(String publisherCode) {
this.publisherCode = publisherCode;
}
public String getBookIsbn() {
return bookIsbn;
}
public void setBookIsbn(String bookIsbn) {
this.bookIsbn = bookIsbn;
}
public String getBookTitle() {
return bookTitle;
}
public void setBookTitle(String bookTitle) {
this.bookTitle = bookTitle;
}
public String getArtist() {
return artist;
}
public void setArtist(String artist) {
this.artist = artist;
}
public String getSong() {
return song;
}
public void setSong(String song) {
this.song = song;
}
public Integer getPageNum() {
return pageNum;
}
public void setPageNum(Integer pageNum) {
this.pageNum = pageNum;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Content)) {
return false;
}
Content other = (Content) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "mlpapp.Content[id=" + id + "]";
}
}
Description
Code description: the controller class
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mlpapp;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
/**
*
* @author depot
*/
public class MLPController {
private EntityManagerFactory emf;
private EntityManager getEntityManager() {
if(emf == null){
emf = Persistence.createEntityManagerFactory("MLPAppPU");
}
return emf.createEntityManager();
}
public Content[] getContent() {
EntityManager em = getEntityManager();
try{
javax.persistence.Query q = em.createQuery("select c from content as c");
return (Content[]) q.getResultList().toArray(new Content[0]);
} finally {
em.close();
}
}
}
Description
Code description:The session bean
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mlpwebapp;
import com.sun.rave.web.ui.appbase.AbstractSessionBean;
import javax.faces.FacesException;
import mlpapp.Content;
import mlpapp.MLPController;
/**
* <p>Session scope data bean for your application. Create properties
* here to represent cached data that should be made available across
* multiple HTTP requests for an individual user.</p>
*
* <p>An instance of this class will be created for you automatically,
* the first time your application evaluates a value binding expression
* or method binding expression that references a managed bean using
* this class.</p>
*
* @version SessionBean1.java
* @version Created on Mar 21, 2009, 2:13:02 AM
* @author depot
*/
public class SessionBean1 extends AbstractSessionBean {
// <editor-fold defaultstate="collapsed" desc="Managed Component Definition">
/**
* <p>Automatically managed component initialization. <strong>WARNING:</strong>
* This method is automatically generated, so any user-specified code inserted
* here is subject to being replaced.</p>
*/
private void _init() throws Exception {
}
// </editor-fold>
/**
* <p>Construct a new session data bean instance.</p>
*/
private Content[] content;
public SessionBean1() {
}
/**
* <p>This method is called when this bean is initially added to
* session scope. Typically, this occurs as a result of evaluating
* a value binding or method binding expression, which utilizes the
* managed bean facility to instantiate this bean and store it into
* session scope.</p>
*
* <p>You may customize this method to initialize and cache data values
* or resources that are required for the lifetime of a particular
* user session.</p>
*/
@Override
public void init() {
// Perform initializations inherited from our superclass
super.init();
// Perform application initialization that must complete
// *before* managed components are initialized
// TODO - add your own initialiation code here
try{
_init();
}catch (Exception e) {
log("SessionBean1 Initialization Failure", e);
throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
}
updateContent();
// <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
// Initialize automatically managed components
// *Note* - this logic should NOT be modified
try {
_init();
} catch (Exception e) {
log("SessionBean1 Initialization Failure", e);
throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
}
// </editor-fold>
// Perform application initialization that must complete
// *after* managed components are initialized
// TODO - add your own initialization code here
}
/**
* <p>This method is called when the session containing it is about to be
* passivated. Typically, this occurs in a distributed servlet container
* when the session is about to be transferred to a different
* container instance, after which the <code>activate()</code> method
* will be called to indicate that the transfer is complete.</p>
*
* <p>You may customize this method to release references to session data
* or resources that can not be serialized with the session itself.</p>
*/
@Override
public void passivate() {
}
/**
* <p>This method is called when the session containing it was
* reactivated.</p>
*
* <p>You may customize this method to reacquire references to session
* data or resources that could not be serialized with the
* session itself.</p>
*/
@Override
public void activate() {
}
/**
* <p>This method is called when this bean is removed from
* session scope. Typically, this occurs as a result of
* the session timing out or being terminated by the application.</p>
*
* <p>You may customize this method to clean up resources allocated
* during the execution of the <code>init()</code> method, or
* at any later time during the lifetime of the application.</p>
*/
@Override
public void destroy() {
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected ApplicationBean1 getApplicationBean1() {
return (ApplicationBean1) getBean("ApplicationBean1");
}
public Content[] getContent() {
return content;
}
public void setContent(Content[] content) {
this.content = content;
}
public void updateContent(){
MLPController mLPController=new MLPController();
content=mLPController.getContent();
}
}
Thanks again.
-ceyesuma
Solution:I would like to know a way to at least learn how I could somehow track what is actually in the content[]. Is this possible. If it is what is the best way to do this?
The solutions related to this code are
Note:
Note: