0

I have an arraylist of employeebean resultEmployeeList set in request scope.. I don't know if i was doing it the right way.. But here is the jstl code used in jsp..

<c:forEach var="element" items="${resultEmployeeList} ">
            <tr>

                <td>
                ${element.empId}
                </td>
                <td> ${element.empname}</td>


            </tr>
        </c:forEach>

when i try to access empId property of employeebean, it shows this error

javax.el.PropertyNotFoundException: Property 'empid' not found on type java.lang.String

Here is the employeebean

public class EmployeeBean {

private int empId;
private String empname;
private boolean exceptionExist;
public EmployeeBean() {
}

public int getEmpId() {
    return empId;
}

public void setEmpId(int empId) {

    this.empId = empId;
}

public EmployeeBean(int empId, String empname) {
    this.empId = empId;
    this.empname = empname;
}

public String getEmpname() {
    return empname;
}

public void setEmpname(String empname) {
    this.empname = empname;
}

public boolean exceptionExist(){
return true;
}

}

This is where i put the resultEmployeeList

public boolean getEmployeesIn(ArrayList<Integer> empids,HttpServletRequest request) {
    ArrayList<EmployeeBean> employeeList=new ArrayList<EmployeeBean>();
    Iterator empidIterator=empids.iterator();
    while(empidIterator.hasNext()){

        employeeList.add(eObject.getEmployee((Integer)empidIterator.next()));
    }
    if(employeeList.isEmpty())
        return false;
    else{
    request.setAttribute("resultEmployeeList", employeeList);
    }
    return true;

Wherein eObject.getEmployee(..) calls this method..

 public EmployeeBean getEmployee(int empId) {

    EmployeeBean eb = new EmployeeBean();
    try {

        String query = "select * from empschema.employee where empid=?";
        ps = con.prepareStatement(query);
        ps.setInt(1, empId);
        ResultSet rs = ps.executeQuery();

        if (!rs.next()) {
            eb=null;
            return eb;

        } else {

                eb.setEmpId(rs.getInt(1));
                eb.setEmpname(rs.getString(2));

        }
    } catch (SQLException ex) {
        Logger.getLogger(EmployeeDAO.class.getName()).log(Level.SEVERE, null, ex);
    }
    return eb;

}
surendhar_s
  • 824
  • 2
  • 12
  • 20
  • Can you post that code where you put list in request scope? – niiraj874u May 06 '14 at 10:35
  • ${resultEmployeeList} this list in request scope... I hope you are setting in the controller – AurA May 06 '14 at 10:35
  • replace ${resultEmployeeList} with ${requestScope.resultEmployeeList} and check – niiraj874u May 06 '14 at 10:41
  • @niiraj874u posted the code.. – surendhar_s May 06 '14 at 10:46
  • surendhar, have you tried using ${requestScope.resultEmployeeList} – niiraj874u May 06 '14 at 10:49
  • @niiraj874u Yea.. tried.. but didnt work out.. – surendhar_s May 06 '14 at 10:55
  • Try iterating the list alone like this `${element}` – Santhosh May 06 '14 at 10:58
  • @san krish this is what i got when iterating [com.app.beans.EmployeeBean@1837f798 [com.app.beans.EmployeeBean@1837f798 com.app.beans.EmployeeBean@2602894] com.app.beans.EmployeeBean@2602894] – surendhar_s May 06 '14 at 11:04
  • Can't get you . did you get the same thing i posted without rendering ? – Santhosh May 06 '14 at 11:06
  • Why dont you try with `c:out` tag ? – Santhosh May 06 '14 at 11:12
  • ${element} is employeebean..hence when i used it in jstl, it showed the reference number.. but my problem is, i couldn't do this ${element.empId} – surendhar_s May 06 '14 at 11:15
  • @sankrish tried that as well.. it showed the same error javax.el.PropertyNotFoundException: Property 'empId' not found on type java.lang.String javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:237) javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:214) javax.el.BeanELResolver.property(BeanELResolver.java:325) javax.el.BeanELResolver.getValue(BeanELResolver.java:85) org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104) – surendhar_s May 06 '14 at 11:17
  • I guess your way of adding the objects into the list seems incorrect – Santhosh May 06 '14 at 11:24
  • You need to add the object into the array list like this `employeeList.add(eb)` to access the getters from the bean – Santhosh May 06 '14 at 11:28
  • Nope..still it has to work.. – surendhar_s May 06 '14 at 11:38
  • NO you shouldnt see the [answer here](http://stackoverflow.com/questions/10855288/javax-el-propertynotfoundexception-property-tname-not-found-on-type-java-lang) and also this [one](http://stackoverflow.com/questions/13807683/property-someproperty-not-found-on-type-java-lang-string) – Santhosh May 06 '14 at 11:43
  • Note the line employeeList.add(eObject.getEmployee()), where eObject.getEmployee() returns EmployeeBean itself.. Not a string or integer[the ones mentioned in ur link] – surendhar_s May 06 '14 at 12:08
  • Are you sure the error is occurring in the code snippet you have shared? Can you share rest of the code(if any) in your jsp? – Priyesh May 06 '14 at 12:28
  • @Priyesh that's all i had in jsp.. c:foreach was inside the body tag.. – surendhar_s May 06 '14 at 12:33

1 Answers1

1

If you have pasted the code as is, then there is an extra space in items="${resultEmployeeList} " after ${resultEmployeeList}. That can cause the variable element to be treated as a String instead of the actual type.

Priyesh
  • 2,041
  • 1
  • 17
  • 25