views:

283

answers:

6
+2  Q: 

DisplayTag error

Hi, I am using the DisplayTag with pagination to display a List objects. The Transactions has a property called 'company' / getCompany() which is the Company object. The Company object contains a String called 'name' / getName().

My code looks like this:

<display:table name="${transactions}" id="transaction" pagesize="2" defaultsort="1">  

<display:column property="id" title="ID" href="showTransactionDetails.html" paramId="id" />
<display:column property="company.name" title="Company Name" sortable="true"    >
<display:column property="status" title="Status" sortable="true">

</display:table>

Here is the strange part.... Everything works great when the first page is displayed and there are a total of 11 pages with each page containing 2 records.

I can click on a page number and see the page advance. But for some strange reason, when I click on page (2-4) I get an exception:

org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Exception: [.LookupUtil] Error looking up property "company.name" in object type "com.replacements.entity.Transaction". Cause: null

(It's also important to note that all of the Transaction records contain a value for the company.name since its a required field in my DB)

+2  A: 

Is it possible that the company is null. That is, you have a transaction with no company in the database.

Vincent Ramdhanie
No, a Company is required in a Transaction and a name is required in a Company. Another strange part is that if I change the pagesize="10" and only see 2 pages, every record is displayed and works fine.
Sam K
+1  A: 

As @Vincent says, likely company is null. You may have a value in your database, but maybe there is an issue where your Transaction class isn't properly reading the db value and setting its company member. Have you tried setting a breakpoint and looking at the Transaction instance?

Marcus
Thanks guys, but all records definitely have values in the database. I am using Hibernate to query the records and adding them to a List.Here is something even more strange I just found:If in the same JSP page I put:<% System.out.println("----------------------------");List<Transaction> transactions = (List<Transaction>)session.getAttribute("transactions");for(Transaction t:transactions){System.out.println(t.getCompany().getName());}%>Not only are all records printed in the System out stream, but the pagination starts working fine.
Sam K
Could you be having a problem with Hibernate trying to lazy-load the rows of your List?
Pointy
+1  A: 

My first guess is that there is an empty company list. I would suggest you print dump to output your transaction results before they get to the display part.

If that’s not the problem I’ve seen display problems caused by special characters. One of the company names might contain a control character or some other non-displayable character.

Ben
A: 

The exception message literally tells that the Transaction is null. Thus, there's apparently a null item in the transaction list behind ${transactions}. Look like a fault in the loading/populating logic of the transaction list. Maybe the last item is null? Or maybe the list is request scoped and dependent from some request parameters which are missing in the subsequent request so that loading/populating the list failed?

For the interested, if Company was null as some suggests, EL would not have error'ed that way. It would have mentioned object type Company instead.

BalusC
+1  A: 

Try changing the name="${transactions}" in the display:table tag to name="transactions".

Assuming you have the transactions collection in the session or request or whatever.

Marcus
Tried that, and got "Nothing found to display. "
Sam K
+1  A: 

I solved it by changing the company property in Hibernate mapping to "lazy=false"

I'm still not sure why the pagination worked from some pages and not all. But this fixed it.

Thank you all for your ideas.

Sam K