开发者

javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property

I am creating Sample Spring MVC a开发者_开发问答pplication. In my Controller class I have define like this:

Map<String, Object> myModel = new HashMap<String, Object>();
        myModel.put("now", now);
        myModel.put("products", this.productManager.getProducts());

        return new ModelAndView("hello", "model", myModel);

When I put following part in my JSP file i got javax.el.PropertyNotFoundException exception

<c:forEach items="${model.products}" var="prod">
        <c:out value="${prod.description}"/> <i>$<c:out value="${prod.price}"/></i><br><br>
    </c:forEach>

Here is my full exception :

javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'description'.

But in my domain class private Sting description property has public getter and setter. That Product class is public one.

Product class:

public class Product implements Serializable {
    private String description;
    private Double price;

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

}

PS:

If I used like this it's working

<c:forEach items="${model.products}" var="prod"  varStatus="status">        
        <c:out value="${model.products[status.count -1].description}"/> <i>$<c:out value="${model.products[status.count -1].price}"/></i><br><br>
    </c:forEach> 

But recommended solution not working :(


This happen when you are passing a String to an EL operation c:forEach instead of an iterable element, in the following example I miss the '$' so it's passing the exact String without variable resolution.

<c:forEach var="o" items="{operations}">

The next is right because operation is a String[] in my code

<c:forEach var="o" items="${operations}">


Maybe check your taglib import:

OLD

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

NEW

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

Is your Product class and its getters accessible? By this I broadly mean are they public?

See http://forum.springsource.org/showthread.php?58420-Problem-with-javax.el.PropertyNotFoundException.


Try this:

<c:forEach items="${model['products']}" var="oneProduct">
    <c:out value="${oneProduct.description}"/> <i>$<c:out value="${oneProduct.price}"/>                            
    </i><br><br>
</c:forEach>

And check the capitalization of you gettters and setters, should be getDescription()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜