DisplayTag Library Question

M

Mongoose

Hi All,

For some reason I'm having trouble with displaying my list data with
the DisplayTag Library . . . I'm new to Struts (and the
DisplayTagLibrary) so hopefully it's something simple . . .

In my implementation class I have a method that uses Hibernate to get
some data from an Oracle Database. The List (in this case called
"results") is returned to the caller . . . which is a Struts Action.
The first part of this file is shown below as well . . .



public List getDefects( ) throws DatastoreException
{
List results = null;
List items = null;

Session session = null;

try
{
session = sessionFactory.openSession( );
Query q = session.createQuery("select DefectID, Description,
PriorityID from Defect");
results = q.list( );
session.close( );
}catch( Exception ex ){
ex.printStackTrace( );
throw DatastoreException.datastoreError(ex);
}
return results;
}




public class TestAction extends Action
{
public TestAction()
{
super();
}

public ActionForward execute (ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws
Exception
{

ActionErrors errors = new ActionErrors();
ActionForward forward = new ActionForward();
// return value
//SubmitForm submitForm = (SubmitForm) form;

try
{

System.out.println("Go Away");

EricEnhancementServiceImpl E = new EricEnhancementServiceImpl();
List results = E.getDefects();

for (ListIterator iter = results.listIterator(); iter.hasNext
() ; )
{
Object[] row = (Object[])iter.next();
Integer id = (Integer)row[0];
String desc = (String)row[1];
Integer priorityid = (Integer)row[2];
}

request.setAttribute("stuff", results);


As you can see in the action the "results" list is stored in
session . . .
The .jsp where I'm just trying to display the results of the data that
is in my list is shown below:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><%@page
language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>

<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@ taglib uri="http://displaytag.sf.net/el" prefix="displayel" %>

<html:html>
<head>
<title>defect</title>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
</head>
<body>

<jsp:include page="strutsmenu.jsp"/>

<display:table name="stuff"/>


</body>
</html:html>

When I try to execute the Struts application I get the memory location
printed instead of the data (like this). As far as I know all .jar
file and .tld files are present.

[Ljava.lang.Object;@64c964c9
[Ljava.lang.Object;@64e164e1
[Ljava.lang.Object;@64f964f9
[Ljava.lang.Object;@650f650f
[Ljava.lang.Object;@65276527
[Ljava.lang.Object;@65406540

Can someone please tell me what I'm doing wrong . . .

Thanks,

Pete
 
A

Arne Vajhøj

Mongoose said:
Hi All,

For some reason I'm having trouble with displaying my list data with
the DisplayTag Library . . . I'm new to Struts (and the
DisplayTagLibrary) so hopefully it's something simple . . .

In my implementation class I have a method that uses Hibernate to get
some data from an Oracle Database. The List (in this case called
"results") is returned to the caller . . . which is a Struts Action.
The first part of this file is shown below as well . . .



public List getDefects( ) throws DatastoreException
{
List results = null;
List items = null;

Session session = null;

try
{
session = sessionFactory.openSession( );
Query q = session.createQuery("select DefectID, Description,
PriorityID from Defect");
results = q.list( );
session.close( );
}catch( Exception ex ){
ex.printStackTrace( );
throw DatastoreException.datastoreError(ex);
}
return results;
}




public class TestAction extends Action
{
public TestAction()
{
super();
}

public ActionForward execute (ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws
Exception
{

ActionErrors errors = new ActionErrors();
ActionForward forward = new ActionForward();
// return value
//SubmitForm submitForm = (SubmitForm) form;

try
{

System.out.println("Go Away");

EricEnhancementServiceImpl E = new EricEnhancementServiceImpl();
List results = E.getDefects();

for (ListIterator iter = results.listIterator(); iter.hasNext
() ; )
{
Object[] row = (Object[])iter.next();
Integer id = (Integer)row[0];
String desc = (String)row[1];
Integer priorityid = (Integer)row[2];
}

request.setAttribute("stuff", results);


As you can see in the action the "results" list is stored in
session . . .
The .jsp where I'm just trying to display the results of the data that
is in my list is shown below:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><%@page
language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>

<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@ taglib uri="http://displaytag.sf.net/el" prefix="displayel" %>

<html:html>
<head>
<title>defect</title>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
</head>
<body>

<jsp:include page="strutsmenu.jsp"/>

<display:table name="stuff"/>


</body>
</html:html>

When I try to execute the Struts application I get the memory location
printed instead of the data (like this). As far as I know all .jar
file and .tld files are present.

[Ljava.lang.Object;@64c964c9
[Ljava.lang.Object;@64e164e1
[Ljava.lang.Object;@64f964f9
[Ljava.lang.Object;@650f650f
[Ljava.lang.Object;@65276527
[Ljava.lang.Object;@65406540

Can someone please tell me what I'm doing wrong . . .

Maybe your Defect class should have a toString method.

Arne
 
D

Daniel Pitts

Arne said:
Mongoose said:
Hi All,

For some reason I'm having trouble with displaying my list data with
the DisplayTag Library . . . I'm new to Struts (and the
DisplayTagLibrary) so hopefully it's something simple . . .

In my implementation class I have a method that uses Hibernate to get
some data from an Oracle Database. The List (in this case called
"results") is returned to the caller . . . which is a Struts Action.
The first part of this file is shown below as well . . .



public List getDefects( ) throws DatastoreException
{
List results = null;
List items = null;

Session session = null;

try
{
session = sessionFactory.openSession( );
Query q = session.createQuery("select DefectID, Description,
PriorityID from Defect");
results = q.list( );
session.close( );
}catch( Exception ex ){
ex.printStackTrace( );
throw DatastoreException.datastoreError(ex);
}
return results;
}




public class TestAction extends Action
{
public TestAction()
{
super();
}

public ActionForward execute (ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws
Exception
{

ActionErrors errors = new ActionErrors();
ActionForward forward = new ActionForward();
// return value
//SubmitForm submitForm = (SubmitForm) form;

try
{

System.out.println("Go Away");

EricEnhancementServiceImpl E = new
EricEnhancementServiceImpl();
List results = E.getDefects();

for (ListIterator iter = results.listIterator();
iter.hasNext
() ; )
{
Object[] row = (Object[])iter.next();
Integer id = (Integer)row[0];
String desc = (String)row[1];
Integer priorityid = (Integer)row[2];
}

request.setAttribute("stuff", results);


As you can see in the action the "results" list is stored in
session . . .
The .jsp where I'm just trying to display the results of the data that
is in my list is shown below:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><%@page
language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>

<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@ taglib uri="http://displaytag.sf.net/el" prefix="displayel" %>

<html:html>
<head>
<title>defect</title>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
</head>
<body>

<jsp:include page="strutsmenu.jsp"/>

<display:table name="stuff"/>


</body>
</html:html>

When I try to execute the Struts application I get the memory location
printed instead of the data (like this). As far as I know all .jar
file and .tld files are present.

[Ljava.lang.Object;@64c964c9
[Ljava.lang.Object;@64e164e1
[Ljava.lang.Object;@64f964f9
[Ljava.lang.Object;@650f650f
[Ljava.lang.Object;@65276527
[Ljava.lang.Object;@65406540

Can someone please tell me what I'm doing wrong . . .

Maybe your Defect class should have a toString method.

Arne
Even worse than that, the ooutput suggests an "Object[]" instance is the
actual object being printed. Perhaps dispaytag's documentation would
illuminate the proper usage.

You may have to transform your Object[] rows into actual Strings,
Objects, or (ick) Maps.
 
M

Mongoose

Arne said:
Mongoose said:
Hi All,
For some reason I'm having trouble with displaying my list data with
the DisplayTag Library . . . I'm new to Struts (and the
DisplayTagLibrary) so hopefully it's something simple . . .
In my implementation class I have a method that uses Hibernate to get
some data from an Oracle Database.  The List (in this case called
"results") is returned to the caller . . . which is a Struts Action.
The first part of this file is shown below as well . . .
public List getDefects( ) throws DatastoreException
{
   List results = null;
   List items = null;
   Session session = null;
    try
    {
         session = sessionFactory.openSession( );
         Query q = session.createQuery("select DefectID, Description,
PriorityID from Defect");
         results = q.list( );
         session.close( );
         }catch( Exception ex ){
         ex.printStackTrace( );
         throw DatastoreException.datastoreError(ex);
     }
         return results;
}
public class TestAction extends Action
{
    public TestAction()
    {
        super();
    }
    public ActionForward execute (ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws
Exception
    {
        ActionErrors errors = new ActionErrors();
        ActionForward forward = new ActionForward();
        // return value
        //SubmitForm submitForm = (SubmitForm) form;
        try
        {
            System.out.println("Go Away");
             EricEnhancementServiceImpl E = new
EricEnhancementServiceImpl();
             List results = E.getDefects();
             for (ListIterator iter = results.listIterator();
iter.hasNext
() ; )
              {
                 Object[] row = (Object[])iter.next();
                 Integer id = (Integer)row[0];
                 String desc = (String)row[1];
                 Integer priorityid = (Integer)row[2];
              }
             request.setAttribute("stuff", results);
As you can see in the action the "results" list is stored in
session . . .
The .jsp where I'm just trying to display the results of the data that
is in my list is shown below:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><%@page
    language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@ taglib uri="http://displaytag.sf.net/el" prefix="displayel" %>
<html:html>
<head>
<title>defect</title>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
</head>
<body>
    <jsp:include page="strutsmenu.jsp"/>
    <display:table name="stuff"/>
</body>
</html:html>
When I try to execute the Struts application I get the memory location
printed instead of the data (like this).  As far as I know all .jar
file and .tld files are present.
[Ljava.lang.Object;@64c964c9
[Ljava.lang.Object;@64e164e1
[Ljava.lang.Object;@64f964f9
[Ljava.lang.Object;@650f650f
[Ljava.lang.Object;@65276527
[Ljava.lang.Object;@65406540
Can someone please tell me what I'm doing wrong . . .
Maybe your Defect class should have a toString method.

Even worse than that, the ooutput suggests an "Object[]" instance is the
actual object being printed.  Perhaps dispaytag's documentation would
illuminate the proper usage.

You may have to transform your Object[] rows into actual Strings,
Objects, or (ick) Maps.

Hmmm, still haven't quite been able to overcome this issue . . . I
definitely have an ArrayList of Objects. Each object is an
instantiation of the class below:

public class Defect extends ActionForm
{

private Integer DefectID;
private String Description;
private Integer PriorityID;

public Integer getDefectID()
{
return DefectID;
}

public void setDefectID(Integer defectID)
{
DefectID = defectID;
}

public String getDescription()
{
return Description;
}

public void setDescription(String description)
{
Description = description;
}

public Integer getPriorityID()
{
return PriorityID;
}

public void setPriorityID(Integer priorityID)
{
PriorityID = priorityID;
}

}

So I have an arraylist of Defect Objects. However, when I try to
execute the following code in the .jsp

<display:table name="Defects" class="displaytable">
<display:column property="Description" />
</display:table>

I get: javax.servlet.ServletException:
javax.servlet.jsp.JspException: Error looking up property
"Description" in object type blah blah blah. And I know there is a
getDescription in there so I'm not sure here . . . still trying to
determine what I'm doing wrong . . .
 
A

Arne Vajhøj

Mongoose said:
Arne said:
Mongoose wrote:
Hi All,
For some reason I'm having trouble with displaying my list data with
the DisplayTag Library . . . I'm new to Struts (and the
DisplayTagLibrary) so hopefully it's something simple . . .
In my implementation class I have a method that uses Hibernate to get
some data from an Oracle Database. The List (in this case called
"results") is returned to the caller . . . which is a Struts Action.
The first part of this file is shown below as well . . .
public List getDefects( ) throws DatastoreException
{
List results = null;
List items = null;
Session session = null;
try
{
session = sessionFactory.openSession( );
Query q = session.createQuery("select DefectID, Description,
PriorityID from Defect");
results = q.list( );
session.close( );
}catch( Exception ex ){
ex.printStackTrace( );
throw DatastoreException.datastoreError(ex);
}
return results;
}
public class TestAction extends Action
{
public TestAction()
{
super();
}
public ActionForward execute (ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws
Exception
{
ActionErrors errors = new ActionErrors();
ActionForward forward = new ActionForward();
// return value
//SubmitForm submitForm = (SubmitForm) form;
try
{
System.out.println("Go Away");
EricEnhancementServiceImpl E = new
EricEnhancementServiceImpl();
List results = E.getDefects();
for (ListIterator iter = results.listIterator();
iter.hasNext
() ; )
{
Object[] row = (Object[])iter.next();
Integer id = (Integer)row[0];
String desc = (String)row[1];
Integer priorityid = (Integer)row[2];
}
request.setAttribute("stuff", results);
As you can see in the action the "results" list is stored in
session . . .
The .jsp where I'm just trying to display the results of the data that
is in my list is shown below:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><%@page
language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@ taglib uri="http://displaytag.sf.net/el" prefix="displayel" %>
<html:html>
<head>
<title>defect</title>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
</head>
<body>
<jsp:include page="strutsmenu.jsp"/>
<display:table name="stuff"/>
</body>
</html:html>
When I try to execute the Struts application I get the memory location
printed instead of the data (like this). As far as I know all .jar
file and .tld files are present.
[Ljava.lang.Object;@64c964c9
[Ljava.lang.Object;@64e164e1
[Ljava.lang.Object;@64f964f9
[Ljava.lang.Object;@650f650f
[Ljava.lang.Object;@65276527
[Ljava.lang.Object;@65406540
Can someone please tell me what I'm doing wrong . . .
Maybe your Defect class should have a toString method.
Arne
Even worse than that, the ooutput suggests an "Object[]" instance is the
actual object being printed. Perhaps dispaytag's documentation would
illuminate the proper usage.

You may have to transform your Object[] rows into actual Strings,
Objects, or (ick) Maps.

Hmmm, still haven't quite been able to overcome this issue . . . I
definitely have an ArrayList of Objects. Each object is an
instantiation of the class below:

public class Defect extends ActionForm
{

private Integer DefectID;
private String Description;
private Integer PriorityID;

public Integer getDefectID()
{
return DefectID;
}

public void setDefectID(Integer defectID)
{
DefectID = defectID;
}

public String getDescription()
{
return Description;
}

public void setDescription(String description)
{
Description = description;
}

public Integer getPriorityID()
{
return PriorityID;
}

public void setPriorityID(Integer priorityID)
{
PriorityID = priorityID;
}

}

So I have an arraylist of Defect Objects. However, when I try to
execute the following code in the .jsp

<display:table name="Defects" class="displaytable">
<display:column property="Description" />
</display:table>

I get: javax.servlet.ServletException:
javax.servlet.jsp.JspException: Error looking up property
"Description" in object type blah blah blah. And I know there is a
getDescription in there so I'm not sure here . . . still trying to
determine what I'm doing wrong . . .

1) I don't think it is good to have the DAL-BLL DTO's extend
extend ActionForm that is PL-CL thingy.

2) I strongly suspect that the problem is:

Query q = session.createQuery("select DefectID, Description, PriorityID
from Defect");

Try:

List results = session.createQuery("FROM Defect").list();

Arne
 
C

ck

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><%@page
        language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>

<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@ taglib uri="http://displaytag.sf.net/el" prefix="displayel" %>

<html:html>
<head>
<title>defect</title>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
</head>
<body>

        <jsp:include page="strutsmenu.jsp"/>

        <display:table name="stuff"/>

</body>
</html:html>

If above code is all that you got in the jsp, the output below is
quite obvious.
[Ljava.lang.Object;@64c964c9
[Ljava.lang.Object;@64e164e1
[Ljava.lang.Object;@64f964f9
[Ljava.lang.Object;@650f650f
[Ljava.lang.Object;@65276527
[Ljava.lang.Object;@65406540

Can someone please tell me what I'm doing wrong . . .
You might want to add the column that you would like to see in the
table
For example

== jsp code ==
<display:table name="persons" id="persons" cellspacing="0"
cellpadding="0">
<display:column property="name"/>
</display:table>
== jsp code end ==

Where Person class has getter and setter for "name"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top