JSFで簡単なブック管理を作成したいと思います。ターゲットに到達できません、JSFでnullが返されました
@Named(value = "bookController")
@SessionScoped
public class BookController implements Serializable {
@EJB
BookFacadeLocal bookFacade;
Book book = new Book();
private List<Book> booklist = new LinkedList<Book>();
/** Creates a new instance of BookController */
public BookController() {
}
public Book getBook() {
if (book == null)
book = new Book();
return book;
}
public void setBook(Book book) {
this.book = book;
}
public List<Book> getBooklist() {
return booklist;
}
public void setBooklist(List<Book> booklist) {
this.booklist = booklist;
}
public String createNewBook()
{
setBook(new Book());
return "createBook";
}
public String saveNewBook()
{
bookFacade.create(book);
booklist=bookFacade.findAll();
return "listBooks";
}
public String createBookList()
{
booklist=bookFacade.findAll();
return "listBooks";
}
}
CreateBookビュー:
<?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://java.sun.com/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
Create Book
<h:form id="createBook">
<h:panelGrid id="grid" columns="2" >
<h:outputLabel value="Title" for="title"></h:outputLabel>
<h:inputText id="title" value="#{bookController.book.title}"></h:inputText>
<h:outputLabel value="Price" for="price"></h:outputLabel>
<h:inputText id="price" value="#{bookController.book.price}"></h:inputText>
<h:outputLabel value="Description" for="description"></h:outputLabel>
<h:inputTextarea id="description" value="#{bookController.book.description}"></h:inputTextarea>
<h:outputLabel value="ISBN" for="isbn"></h:outputLabel>
<h:inputText id="isbn" value="#{bookController.book.isbn}"></h:inputText>
<h:outputLabel value="Pages" for="pages"></h:outputLabel>
<h:inputText id="pages" value="#{bookController.book.nbOfPage}"></h:inputText>
<h:outputLabel value="Illustration" for="illustrations"></h:outputLabel>
<h:selectBooleanCheckbox id="illustrations" value="#{bookController.book.illustrations}"> </h:selectBooleanCheckbox>
<h:panelGroup> </h:panelGroup>
<h:commandButton id="submit" value ="Save" action="#{bookController.saveNewBook}"> </h:commandButton>
</h:panelGrid>
</h:form>
</h:body>
</html>
のweb.xml:私は3.1
帳コントローラGlashfishサーバーを使用しています
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
BookController:#{bookController}
- - > BookController: [email protected]エラー:
/createBook.xhtml @13,82 value="#{bookController.book.title}": Target Unreachable, 'null' returned null
hy! /WEB-INF/beans.xmlにxml宣言がいくつか存在します...私のコントローラの注釈を変更しましたが、同じエラーが発生しました。 – test123123
'beans.xml'で何を宣言しましたか?アノテーションをすべてオーバーライドするBean登録を複製したようです。 – BalusC
<?xml version = "1.0" encoding = "UTF-8"?> –
test123123