/myPage.xhtml @ 26,75 value =“#{var.attribute}”:在类型com.sources.Class上找不到属性'属性'

时间:2014-01-16 14:55:10

标签: java jsf javabeans

我遇到了一些我无法解决的问题。我正在做一个h:dataTable,有一些我可以访问的属性,有些属性我没有。不知道为什么......这是代码:

myPage.xhtml:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">

<h:head></h:head>

<h:body>
    <ui:composition template="/WEB-INF/templates/basic.xhtml">
        <ui:define name="content">
            <h:dataTable value="#{data.result}" var="table" width="30%" border="1">
                <h:column>
                    <h:graphicImage value="#{table.image}" width="200" height="200" />
                </h:column>
                <h:column>
                    #{table.name}
                </h:column>
                <h:column>
                    #{table.description}
                </h:column>
            </h:dataTable>
        </ui:define>
    </ui:composition>
</h:body>
</html>

这是Data.java:

package com.sources;

import java.util.List;

public class Data {
    private List<Article> result;

    public Data() {
        // name, description, image
        result.add(new Article("Tales of", "game", "/Images/" + "image.jpg"));
        result.add(new Article("Harry potter", "book1", "/Images/" + "image.jpg"));
        result.add(new Article("Harry potter", "book2", "/Images/" + "image.jpg"));
    }

    public List<Article> getResult() {
        return result;
    }
}

"/Images/" + "image.jpg"路径是正确的,如果我在"/Images/image.jpg" h:graphicImage中写value,它就会正确显示。

完成后,Article.java:

package com.sources;

import java.util.List;

public class Article {
    private String name;
    private String description;
    private String image;

    public Article() {}

    public Article(String name, String description, String image) {
        this.setName(name);
        this.setDescription(description);
        this.setImage(image);
    }

    public String getName() {
        return name;
    }

    public void setName(final String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

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

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }
}

在myPage.xhtml中,我可以访问#{table.name}#{table.description},但不能访问#{table.image}

以下是我收到的错误:/myPage.xhtml @26,75 value="#{table.image}": Property 'image' not found on type com.sources.Article

0 个答案:

没有答案