我已经创建了一个简单的XHTML文件和相应的Java Bean。在Java Bean内部,我用我的自定义类"FilePreview“的对象生成了一个ArrayList,它是在另一个包中定义的(当然,我将它导入到了Bean中)。在我的XHTML-File中,我使用ui-repeat来迭代列表并显示每个元素。我尝试使用get-Methods访问我的对象的属性。
我的XHTML-文件
<?xml version='1.0' encoding='UTF-8' ?>
<!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:b="http://bootsfaces.net/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<link href="css/stylesheet.css" rel="stylesheet" type="text/css" />
</h:head>
<body>
<ui:composition template="./template.xhtml">
<ui:define name="title">
Dateien
</ui:define>
<ui:define name="content">
<b:container>
<ui:repeat value="#{FileBean.files}" var="files">
<b:panel title="#{files.headline}" look="primary">
<h:outputText value="#{files.description}" />
</b:panel>
<b:alert class= "file" severity="success"><strong>#{files.headline}</strong><br></br> <span>#{files.description}</span></b:alert>
</ui:repeat>
</b:container>
</ui:define>
</ui:composition>
</body>
</html>我的JavaBean:
import de.unibremen.st.gradelog.model.FilePreview;
import java.util.ArrayList;
@ManagedBean(name = "FileBean")
@SessionScoped
public class FileBean implements Serializable {
// private DBHandler handler;
private ArrayList<FilePreview> files;
public void create() {
files = new ArrayList();
files.add(new FilePreview("Hausordnung",
"Anbei findet Ihr die aktualisierte Hausordnung. Bitte gründlich lesen!",
null, null, null));
}
public ArrayList getFiles() {
/**
* DBHandler.getFiles(userID);
*/
System.out.println("Lese die Dateien aus.");
create();
return files;
}
}最后是FilePreview类:
package de.unibremen.st.gradelog.model.FilePreview
public class FilePreview {
private String headline, description, authorID, fileID;
private File file;
public FilePreview(String headline, String description, String authorID,
String fileID, File file) {
this.headline = headline;
this.description = description;
this.authorID = authorID;
this.fileID = fileID;
this.file = file;
}
public String getHeadline() {
return headline;
}
//... more simple getters and setters
}看起来一切正常,只要找到,但当我运行应用程序并访问我的新页面时,我得到了以下错误:
Schwerwiegend: Error Rendering View[/files.xhtml]
javax.el.ELException: /files.xhtml @51,82 value="#{FileBean.files}": java.lang.NoClassDefFoundError: de/unibremen/st/gradelog/model/FilePreview
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
at com.sun.faces.facelets.component.UIRepeat.getValue(UIRepeat.java:279)
at com.sun.faces.facelets.component.UIRepeat.getDataModel(UIRepeat.java:255)
...
Caused by: javax.el.ELException: java.lang.NoClassDefFoundError: de/unibremen/st/gradelog/model/FilePreview
at javax.el.BeanELResolver.getValue(BeanELResolver.java:368)我必须以某种方式让JSF知道这个类吗?我正在处理一个现有的JSF项目,当我尝试对一个新项目做同样的事情时,一切都运行得很好。
有没有人知道这是什么原因?
发布于 2017-02-08 18:19:10
您必须生成一个faces-config.xml文件,在该文件中声明您的托管bean为FileBean。你必须这样做:
https://stackoverflow.com/questions/42109546
复制相似问题