Primefaces选项卡视图在提交/发布时在控制器类中设置空值
以下是场景: 用户将获得一个包含两个不同选项卡的Primefaces选项卡视图在提交/发布时在控制器类中设置空值,primefaces,jsf-2.2,Primefaces,Jsf 2.2,以下是场景: 用户将获得一个包含两个不同选项卡的TabView组件。第一个选项卡包含对象人员的输入字段。第二个选项卡包含对象书籍的输入字段。除此之外,第二个选项卡显示Book对象的列表 用户应该首先输入人员的详细信息,然后切换到第二个选项卡,并将书籍添加到书籍列表中。我们就这么说吧 以下表单嵌入到模板中,并包含选项卡视图: <h:form id="personBookForm"> <p:log id="personBookLog"></p:log>
TabView
组件。第一个选项卡包含对象人员的输入字段。第二个选项卡包含对象书籍的输入字段。除此之外,第二个选项卡显示Book
对象的列表
用户应该首先输入人员的详细信息,然后切换到第二个选项卡,并将书籍添加到书籍列表中。我们就这么说吧
以下表单嵌入到模板中,并包含选项卡视图
:
<h:form id="personBookForm">
<p:log id="personBookLog"></p:log>
<p:panel id="personToggleablePanel" toggleable="true" collapsed="false"
header="Passionate book lovers" toggleSpeed="300">
<f:facet name="actions">
<p:commandButton id="savePersonBookButton"
action="#{personController.savePerson}" icon="ui-icon-disk"
process="@form" />
</f:facet>
<p:tabView id="personBookTabView">
<p:tab id="personTab" title="Person">
<p:panelGrid id="personPanelGrid" columns="1">
<p:inputText id="nameInput"
value="#{personController.currentPerson.name}" />
<p:inputText id="surnameInput"
value="#{personController.currentPerson.surname}" />
</p:panelGrid>
</p:tab>
<p:tab id="bookTab" title="Books">
<p:panelGrid id="bookPanelGrid">
<p:inputText id="titleInput"
value="#{personController.currentBook.title}" />
</p:panelGrid>
<p:dataTable id="bookTable" var="book"
value="#{personController.bookList}" rowKey="#{book.id}"
selectionMode="single" selection="#{personController.currentBook}">
<f:facet name="header">
<p:commandButton id="addBookButton" icon="ui-icon-plusthick"
style="float:right" />
<p:commandButton id="removeBookButton" icon="ui-icon-minusthick"
style="float:right" />
<p:commandButton id="refreshBookTableButton"
icon="ui-icon-refresh" style="float:right;" />
</f:facet>
<p:column headerText="Title">
<h:outputText value="#{book.title}" />
</p:column>
</p:dataTable>
</p:tab>
</p:tabView>
</p:panel>
</h:form>
Book.java
:
public class Book {
private Long id;
private String title;
public Book() { }
public Book(Long id, String title) {
this.id = id;
this.title = title;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Override
public String toString() {
return title;
}
}
public class Person {
private String name;
private String surname;
private List<Book> books;
public Person() { }
public Person(String name, String surname) {
this.name = name;
this.surname = surname;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public List<Book> getBooks() {
return books;
}
public void setBooks(List<Book> books) {
this.books = books;
}
@Override
public String toString() {
return name + " " + surname;
}
}
Person.java
:
public class Book {
private Long id;
private String title;
public Book() { }
public Book(Long id, String title) {
this.id = id;
this.title = title;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Override
public String toString() {
return title;
}
}
public class Person {
private String name;
private String surname;
private List<Book> books;
public Person() { }
public Person(String name, String surname) {
this.name = name;
this.surname = surname;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public List<Book> getBooks() {
return books;
}
public void setBooks(List<Book> books) {
this.books = books;
}
@Override
public String toString() {
return name + " " + surname;
}
}
公共类人物{
私有字符串名称;
私家姓;
私人书目;
公众人物(){}
公众人物(字符串名称、字符串姓氏){
this.name=名称;
this.姓氏=姓氏;
}
公共字符串getName(){
返回名称;
}
公共void集合名(字符串名){
this.name=名称;
}
公共字符串getNames(){
返回姓氏;
}
public void setSurname(字符串姓氏){
this.姓氏=姓氏;
}
公共列表getBooks(){
还书;
}
公共书籍(列表书籍){
这本书=书;
}
@凌驾
公共字符串toString(){
返回姓名+“”+姓氏;
}
}
现在,每次提交表单时,Book
对象(请参见控制器类中的currentBook
)都设置为null
我发现,如果
process=@form
是否已设置
- 按[code>Enter
或单击[code>commandButton
(无论如何,为什么会这样?!)提交表单
您可以设置书本
对象的值,也可以不设置
您忽略了外部面板
您在面板中拉出表单
元素
您可以移除面板
我不希望Book
对象设置为null
如果从视图中删除数据表
,则一切正常
为什么呢?这是你想要的行为吗?有人能解释一下发生了什么吗
先谢谢你