Collector Primefaces NÃO FUNCIONA!

0 respostas
jsfprimefaces
V

Boa noite a todos!

Estou testando o collector do showcase do Primefaces, porém, mesmo realizando o exemplo deles, não funciona!

Visão HTML

</head>
<body>
    <h:form id="form">
        <p:growl id="msgs" />
        <p:panel header="Create a new book" style="margin-bottom:20px; height: 300px">
            <h:panelGrid columns="2" cellpadding="5">
                <h:outputLabel value="Title : *" for="txt_title"></h:outputLabel>
                <p:inputText id="txt_title" value="#{collectorView.book.title}" required="true"/>

                <h:outputLabel value="Author : *" for="txt_author"></h:outputLabel>
                <p:inputText id="txt_author" value="#{collectorView.book.author}" required="true"/>

                <p:commandButton id="btn_reset" value="Reset" type="reset"/>
                <p:commandButton id="btn_add" value="Add" update="books msgs @parent" action="#{collectorView.reinit()}" >
                    <p:collector value="#{collectorView.book}" addTo="#{collectorView.books}" unique="true"/>
                </p:commandButton>
            </h:panelGrid>
        </p:panel>

        <p:outputPanel id="books">
            <p:dataTable value="#{collectorView.books}" var="book" id="booksTable">

                <p:column headerText="Title">
                    <h:outputText value="#{book.title}" />
                </p:column>

                <p:column headerText="Author">
                    <f:facet name="header">
                        <h:outputText value="Author" />
                    </f:facet>
                    <h:outputText value="#{book.author}" />
                </p:column>

                <p:column headerText="Action">
                    <p:commandLink value="Remove" update=":form:books" process=":form:books">
                        <p:collector value="#{book}" removeFrom="#{collectorView.books}" unique="true"/>
                    </p:commandLink>
                </p:column>

            </p:dataTable>
        </p:outputPanel>
    </h:form>
</body>

Modelo

package modelo;

import java.io.Serializable;
import java.util.Objects;

public class Book implements Serializable {

private String title;
private String author;
private String publisher;
private Integer pages;

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

public String getAuthor() {
    return author;
}

public void setAuthor(String author) {
    this.author = author;
}

public String getPublisher() {
    return publisher;
}

public void setPublisher(String publisher) {
    this.publisher = publisher;
}

public Integer getPages() {
    return pages;
}

public void setPages(Integer pages) {
    this.pages = pages;
}

public boolean equals(Object obj) {
 
    Book book = (Book) obj;
     
    return (book.getTitle() != null && book.getTitle().equals(title)) && (book.getAuthor() != null && book.getAuthor().equals(author));
}

public int hashCode() {
    int hash = 1;
    if(title != null)
        hash = hash * 31 + title.hashCode();
     
    if(author != null)
        hash = hash * 29 + author.hashCode();

    return hash;
}

}

Bean
package bean;

/**

  • @author Vagner J Santos (VJS)
  • @Date 20200319
  • @version 2020.0.0
    */
    import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.List;
import modelo.Book;

import javax.annotation.PostConstruct;

import javax.faces.application.FacesMessage;

import javax.faces.context.FacesContext;

import org.springframework.context.annotation.Scope;

import org.springframework.stereotype.Controller;
<a class="mention" href="/u/controller">@Controller</a>(“collectorView”)

@Scope(“view”)

public class CollectorView implements Serializable {
private Book book;
 
private List<Book> books;
 
@PostConstruct
public void init() {
    book = new Book();
    books = new ArrayList<Book>();
     
}
 
public void createNew() {
    if(books.contains(book)) {
        FacesMessage msg = new FacesMessage("Dublicated", "This book has already been added");
        FacesContext.getCurrentInstance().addMessage(null, msg);
    } 
    else {
        books.add(book);
        book = new Book();
    }
}
 
public String reinit() {
    book = new Book();
     
    return null;
}

public Book getBook() {
    return book;
}

public List<Book> getBooks() {
    return books;
}

}

Alguém consegue me ajudar!

Desde já, obrigado!

Criado 5 de abril de 2020
Respostas 0
Participantes 1