Ahmed Soliman
Ahmed Soliman

Reputation: 365

pass map key attribute from servlet to jsp

I want to get name of employee in a LinkedHashMap key from servlet to jsp.

I have this code in java class View.java

LinkedHashMap<Employee, LinkedHashMap<Skill, String>>() employeeSkills = new LinkedHashMap<Employee, LinkedHashMap<Skill, String>>();

Class View has setters and getters for employeeSkills.

Class Employee has name and id attributes with setters and getters.

JSP Code:

< c:forEach var="employeeSkills" items="${employeeSkills}" >
    <td>${employeeSkills.key.name}</td>
</c:forEach>

but i get this error

javax.el.PropertyNotFoundException: Property 'name' not readable on type java.lang.String

Employee Class:

    class Employee{
    String id;
    String name;
    /**
     * @return the id
     */
    public String getId() {
        return id;
    }
    /**
     * @param id the id to set
     */
    public void setId(String id) {
        this.id = id;
    }
    /**
     * @return the name
     */
    public String getName() {
        return name;
    }
    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }
    public Employee(String id, String name) {
        super();
        this.id = id;
        this.name = name;
    }


}

Upvotes: 1

Views: 2451

Answers (3)

Ahmed Soliman
Ahmed Soliman

Reputation: 365

Make class employee public then the jsp works perfect

Upvotes: 0

Alex
Alex

Reputation: 11579

Try this (call var differently):

<c:forEach var="emplSkill" items="${employeeSkills}" >
    <td>${emplSkill.key.name}</td>
</c:forEach>

Upvotes: 1

Philipp Sander
Philipp Sander

Reputation: 10249

remove the .name and you're fine

Upvotes: 1

Related Questions