1

Greetings,

I'm attempting to write my first Java Bean + JSP page from scratch. However, I'm using a 2D array which is populated with arbitrary values, and I'm now getting an exception when I run the JSP saying that the array property cannot be found:

JSP Exception: javax.el.PropertyNotFoundException: Property 'utilTableVals' not found on  type diskUtil.tester

Here is my bean code:

package diskUtil;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.*;
import java.lang.*;
import java.io.*;


public class tester{

//public String [][] utilTableVals;

String [][] utilTableVals = new String[20][20];

/***
bean's properties accessor
***/

/*public String[][] getUtilTableVals() { 
                return utilTableVals;
        }*/


public static String[][] getUtilTableVals()throws Exception{

tester du1 = new tester();
//String [][] utilTableVals = new String[20][20];

int i=0;
int j=0;

int row=0;
int col=0;
int result=0;


for(int r = 0; r < du1.utilTableVals.length; r++)
 {
     for(int c = 0 ; c < du1.utilTableVals[r].length; c++)
     {
        result = r+c;
          du1.utilTableVals[r][c]=Integer.toString(result);
         //System.out.print(" " + utilTableVals[r][c]);
     }
}

return du1.utilTableVals;

}//end getUtilTableVals

My JSP Code is here:

<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<hmtl>
<head>
<title>Disk Utilization Page</title>
</head>
<body>
<h1>DISK UTILZATION REPORT</h1>
<br>

<jsp:useBean id="diskUtilData" scope="request" class="diskUtil.tester" />

<table>
<c:forEach var="celldata" items="${diskUtilData.utilTableVals}">
        <tr>
        <c:forEach var="col" items="${celldata}">
                <td>
                <c:out value="${col}" />
                ${col}
                <p>hello</p>
                </td>
        </c:forEach>
</c:forEach>
        </tr>


</table>
</body>
</html>

Could someone please have a look? Thanks in advance.

-TU

Asaph
  • 159,146
  • 25
  • 197
  • 199
T. Ujasiri
  • 317
  • 1
  • 3
  • 14

3 Answers3

0

The getter method should be public and non static. You should also preferably do the populating in the bean's constructor or action method, not in the getter.

public class Tester { // Classnames ought to start with uppercase.

    private String[][] utilTableVals; // Properties ought to be private.

    public Tester() {
        utilTableVals = new String[20][20];
        // ... Preparing ought to be done in the constructor.
    }

    public String[][] getUtilTableVals() { // Getter ought to be public and non-static.
        return utilTableVals; // Getter should do nothing more than just returning property.
    }

}

Finally, I strongly recommend to use a collection of Javabeans instead of a 2D array. See also Places where JavaBeans are used? This is much more clear, efficient and self-documenting than using plain arrays.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

Make getUtilTableVals() non static. <jsp:useBean> creates an instance of tester. When you reference it in an EL expression, it will call a non-static method.

Asaph
  • 159,146
  • 25
  • 197
  • 199
0

The static method getUtilTableVals() from the type Tester should be only accessed in a static way. Only non static methods get call in your EL Expression.

DarthJDG
  • 16,511
  • 11
  • 49
  • 56
Suresh Babu K
  • 18
  • 1
  • 3