【发布时间】:2023-04-03 08:36:01
【问题描述】:
当我使用列出的项目运行 JSF 时,我会出现第一部分,我可以在其中成功输入详细信息,但它们不会像我希望的那样显示在屏幕上!各位大神帮忙看看:
这是我的 index.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:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>JSF Tester</title>
</h:head>
<h:body>
<h:form>
First name: <h:inputText value="#{PersonController.current.firstName}"/>
Last name: <h:inputText value="#{PersonController.current.lastName}"/>
Birth date: (mm-dd-yyyy) <h:inputText value="#{PersonController.current.date}">
<f:convertDateTime dateStyle="full" type="date" timeZone="CST" pattern="MM-dd-yyyy"/>
</h:inputText>
<h:commandButton value="Submit Person" action="#{PersonController.savePerson()}" />
<h:dataTable var="persons" value="#{PersonController.current}">
<h:column>
<f:facet name="header">First Name</f:facet>
#{PersonController.current.firstName}
</h:column>
<h:column>
<f:facet name="header">Last Name</f:facet>
#{PersonController.current.lastName}
</h:column>
<h:column>
<f:facet name="header">Date</f:facet>
#{PersonController.current.date}
</h:column>
</h:dataTable>
</h:form>
</h:body>
</html>
这是我的包含 ArrayList 的类:
/**
$ Id: PersonController.java v1.0, 7/16/2014
$ Name: $
*/
package org.usd.csci.person.jsf;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
/**
*
* @author
*/
@ManagedBean(name="PersonController")
@SessionScoped
public class PersonController implements Serializable {
Person current = new Person();
List<Person> persons = new ArrayList<Person>();
/**
* Creates a new instance of PersonController
*/
public PersonController() {
}
public Person getCurrent() {
return current;
}
public List<Person> getPersons() {
return persons;
}
public void savePerson() {
persons.add(current);
current = new Person();
}
}
【问题讨论】:
-
你好吗
want them to