for representante this problem i will use the showcase exaplames "Collector http://www.primefaces.org/showcase/ui/collector.jsf and datatable Instant Row Selection
http://www.primefaces.org/showcase/ui/d ... nstant.jsf
when I press add , the code throw a exception
javax.faces.component.UpdateModelException: javax.el.PropertyNotFoundException: /Test.xhtml @91,65 value="#{createBookBean.book.editorial}": Target Unreachable, 'book' returned null
So, when i change de inputText in the p:dialog by a outputText works fine, Any idea?
Please somebody help me!!! i hope your comments
this is the code xhtml
Code: Select all
<ui:define name="content">
<h:form id="form">
<p:panel header="Create a new book">
<h:panelGrid columns="2">
<h:outputLabel value="Title : *" for="txt_title"></h:outputLabel>
<h:inputText id="txt_title" value="#{createBookBean.titulo}" required="true"/>
<h:outputLabel value="Author : *" for="txt_author"></h:outputLabel>
<h:inputText id="txt_author" value="#{createBookBean.autor}" required="true"/>
<p:commandButton value="Reset" type="reset"/>
<p:commandButton value="Add" update="books" action = "#{createBookBean.reinit}" actionListener = "#{createBookBean.add}"/>
</h:panelGrid>
</p:panel>
<p:ajaxStatus style="width:16px;height:16px;">
<f:facet name="start">
<h:graphicImage value="../design/ajaxloading.gif" />
</f:facet>
<f:facet name="complete">
<h:outputText value="" />
</f:facet>
</p:ajaxStatus>
<p:outputPanel id="books">
<p:dataTable id="entries" value="#{createBookBean.books}" var="book" emptyMessage="No entries found" dynamic="true"
selection="#{createBookBean.book}" selectionMode="single" onselectComplete="carDialog.show()" update="display" >
<p:column>
<f:facet name="header">
<h:outputText value="Title" />
</f:facet>
<h:outputText value="#{book.title}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Author" />
</f:facet>
<h:outputText value="#{book.author}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Operation" />
</f:facet>
<p:commandLink value="Remove" update="books">
<p:collector value="#{book}" removeFrom="#{createBookBean.books}" />
</p:commandLink>
</p:column>
<p:column style="width:32px">
<p:commandButton update="display" oncomplete="carDialog.show()" >
<f:setPropertyActionListener value="#{book}" target="#{createBookBean.book}" />
</p:commandButton>
</p:column>
</p:dataTable>
</p:outputPanel>
<p:dialog header="Car Detail" widgetVar="carDialog" resizable="false"
width="200" modal="true" draggable="false">
<h:panelGrid id="display" columns="2" cellpadding="4">
<h:inputText value="#{createBookBean.book.editorial}" />
</h:panelGrid>
</p:dialog>
</h:form>
</ui:define>
Code: Select all
@ManagedBean(name="createBookBean")
@ViewScoped
public class CreateBookBean implements Serializable{
/**
*
*/
private static final long serialVersionUID = -4760165510561347983L;
private Book book = new Book();
private String titulo;
private String autor;
private List<Book> books = new ArrayList<Book>();
private BookService bookService = new BookServiceImpl();
public CreateBookBean(){
books = new ArrayList<Book>();
book = new Book();
bookService = new BookServiceImpl();
}
public String reinit() {
Book s= new Book();
s.setAuthor(autor);
s.setTitle(titulo);
book = s;
return null;
}
public Book getBook() {
return book;
}
public void setBook(Book book) {
this.book = book;
}
public List<Book> getBooks() {
return books;
}
public void setBooks(List<Book> books) {
this.books = books;
}
public void add(ActionEvent e){
Book s= new Book();
s.setAuthor(autor);
s.setTitle(titulo);
book = s;
books.add(book);
}
public void setTitulo(String titulo) {
this.titulo = titulo;
}
public String getTitulo() {
return titulo;
}
public void setAutor(String autor) {
this.autor = autor;
}
public String getAutor() {
return autor;
}
}
Code: Select all
/*
* Copyright 2009 Prime Technology.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package bean;
import java.io.Serializable;
public class Book implements Serializable {
/**
*
*/
private static final long serialVersionUID = 5245540204809648658L;
/**
*
*/
private String title;
private String editorial;
private String genero;
private String author;
private String publisher;
private Integer pages;
public Book(){
}
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) {
if(!(obj instanceof Book))
return false;
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;
}
public void setEditorial(String editorial) {
this.editorial = editorial;
}
public String getEditorial() {
return editorial;
}
public void setGenero(String genero) {
this.genero = genero;
}
public String getGenero() {
return genero;
}
}