Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7022919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:38:39+00:00 2026-05-27T23:38:39+00:00

I want to create a simple Book Management in JSF. I am using Glashfish

  • 0

I want to create a simple Book Management in JSF. I am using Glashfish Server 3.1

Book Controller:

@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 View:

<?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:

<?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: at.em.controller.BookController@107dd383

Error:

/createBook.xhtml @13,82 value=”#{bookController.book.title}”: Target
Unreachable, ‘null’ returned null

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:38:40+00:00Added an answer on May 27, 2026 at 11:38 pm

    /createBook.xhtml @13,82 value=”#{bookController.book.title}”: Target Unreachable, ‘null’ returned null

    The #{bookController} is not available anywhere in the scope. This is normally the responsibility of @Named annotation. This annotation will only be scanned on webapp’s startup when there’s a /WEB-INF/beans.xml file present. So make sure that that file is present (it can be kept empty).

    Alternatively, you can also just use the standard JSF annotations:

    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.ViewScoped;
    
    @ManagedBean
    @ViewScoped
    public class BookController {
    
        // ...
    
    }
    

    (note that I didn’t use javax.faces.bean.SessionScoped because that’s the wrong scope for a normal controller; if it was used, the same bean instance would be shared among multiple browser tabs/windows in the same session which would only lead to unintuitive webapp behaviour)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a simple http proxy server that does some very basic
I want to create a simple box with a header bar containing a title
I want to create a simple bit of JS code that creates an image
I want to create a simple bash script to launch a Java program on
I want to create a simple user registration form with First / Last name,
I want to create a simple transaction on my Web Site where after the
I want to create a simple CMS for my asp.net-mvc site. Will I save
I want to create a simple multiline Alert popup Alert.show(Blah\\nBlah) shows Blah\nBlah when what
I want to create a simple batch file that would perform some Visual Studio
I want to create a simple menu function which can call it example get_menu()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.