这是我的jsf页面,其中我已经尝试了很好的满足对java bean对象的属性的要求。我已经检查了这个网站的所有问题,但似乎有所帮助。我不知道是什么问题,我的代码datatable doesnot呈现数据通过链接列表从数据库中的jsf
<h:dataTable value="#{contact.getPeopleList()}" var="data">
<h:column>
<f:facet name="header">ID</f:facet>
<h:outputText value="#{data.id}"/>
</h:column>
<h:column>
<f:facet name="header">Name</f:facet>
<h:outputText value="#{persons.name}"/>
</h:column>
<h:column>
<f:facet name="header">Mobile Number</f:facet>
#{persons.mobilenumber}
</h:column>
<h:column>
<f:facet name="header">Phone Number</f:facet>
#{persons.telephone}
</h:column>
<h:column>
<f:facet name="header">Address</f:facet>
#{persons.address}
</h:column>
</h:dataTable>
</h:body>
这一个是我的联系类在我所注入Person类
@Named
@RequestScoped
public class Contact {
private Person person;
@PostConstruct
public void init(){
this.person=new Person();
}
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
public String onSubmit(){
ContactDAO doaContact=new ContactDAO();
doaContact.insertContact(person);
return "contactpage";
}
public List<Person> getPeopleList(){
ContactDAO doaContact=new ContactDAO();
List<Person> personList =doaContact.getAll();
return personList;
}
}
package np.com.drose.beans;
import java.util.List;
import np.com.drose.doa.ContactDAO;
public class Person {
private int id;
private String name;
private int mobilenumber;
private int telephone;
private String address;
public Person() {
}
public Person(int id, String name, int mobilenumber, int telephone, String address) {
this.id = id;
this.name = name;
this.mobilenumber = mobilenumber;
this.telephone = telephone;
this.address = address;
}
public Person(String name, int mobilenumber, int telephone, String address) {
this.name = name;
this.mobilenumber = mobilenumber;
this.telephone = telephone;
this.address = address;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getMobilenumber() {
return mobilenumber;
}
public void setMobilenumber(int mobilenumber) {
this.mobilenumber = mobilenumber;
}
public int getTelephone() {
return telephone;
}
public void setTelephone(int telephone) {
this.telephone = telephone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
在这里我得到得到Person类的属性数据访问对象类困惑,我似乎无法找到我做错了什么,为什么我的代码不是从数据库呈现数据
public List<Person> getAll(){
List<Person> contactList= new LinkedList<>();
String sql="Select * from contact";
try{
conn = DataConnection.getConnetion();
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next()){
Person person=new Person(rs.getInt("id"),rs.getString("name"),rs.getInt("mobilenumber"),rs.getInt("telephone"),rs.getString("address"));
contactList.add(person);
}
}catch(Exception EX){
EX.printStackTrace();
}
return contactList;
}
要排除网页浏览器中的一个和其他右键页面并执行“查看页面源代码”。你究竟看到了什么?您是否看到未解析的JSF源代码或其生成的HTML输出?而且,您是否已经调试了Java代码以查看它是否实际被调用? – BalusC
/contactpage.xhtml @ 10,66 value =“#{contact.getPeopleList}”:类'np.com.drose.beans.Contact'没有属性'getPeopleList'。 –