title: JSF 2: h:link and getrowdata
body: <p>If I have a <code>h:dataTable</code> in <strong>books.xhtml</strong> providing a list of records and I want to view a particular record, then add or edit that record, currently I have this:</p>
  
  <pre><code>&lt;h:dataTable #{BookBean.books}" var="books"&gt;
     &lt;h:link outcome="bookview" value="#{books[1]}"&gt;
        &lt;f:param name="id" value="#{books[2]}" /&gt;
     &lt;/h:link&gt;
  &lt;/h:dataTable&gt;
  </code></pre>
  
  <p>I found out that I need to include <code>&lt;f:param&gt;</code> in order to show the CSS status of clicked link; otherwise if I don't have <code>&lt;f:param&gt;</code>, every time I clicked on a link rendered by h:link tags in the codes above, all links are changed to CSS clicked status.</p>
  
  <p>Also, I read somewhere about the <code>getrowdata()</code> but I haven't been able to get it work. Is this a better alternative to using <code>&lt;f:param&gt;</code>?</p>
  
  <p>I have tried the <code>getrowdata()</code> method in my BookBean class as followed:</p>
  
  <pre><code>private DataModel&lt;BookModel&gt; books;
  private BookModel currentBook;
  
  public String view()
  {
       currentBook = books.getRowData();
       return "bookview";
  }
  </code></pre>
  
  <p>and in bookview.xhtml I have this:</p>
  
  <pre><code>&lt;h:dataTable value="#{BookBean.view}" var="item"&gt;
      ... // render content here
  &lt;h:dataTable&gt;
  </code></pre>
  
  <p>but I get an error about the property not found. Sorry for asking this question but I still don't understand yet some of the powerful features of JSF 2. Can some expert who understand the usage of <code>h:link</code> and <code>getrowdata</code> please explain to me in layman terms or perhaps with some basic code example. Thank you.</p>
  
  <p><strong>UPDATE:</strong>
  Changed classes based on @BalusC suggestions below. <strong>BookModel</strong> class is:</p>
  
  <pre><code>@Entity
  public class BookModel implements Serializable
  {
     private Long id;
     private String title;
     private String author;   
  
     // getters and setters here
   }
  </code></pre>
  
  <p>The <strong>BookService</strong> class looks like this:</p>
  
  <pre><code>@Stateless
  public class BookService
  {
      @PersistenceContext(unitName = "persistentUnit")
      protected EntityManager entityManager;
  
      public BookModel create() {
         return new BookModel();
      }
  
      public void delete(BookModel bookModel) {
         bookModel = entityManager.merge(bookModel);
         entityManager.remove(bookModel);
      }
  
      public BookModel update(BookModel bookModel) {
         return entityManager.merge(bookModel);
      }
  
      public BookModel find(Long id) {
         return entityManager.find(BookModel.class, id);
      }
  }
  </code></pre>
  
  <p>The <strong>BookBean</strong> class is:</p>
  
  <pre><code>@ManagedBean(name = "bookBean")
  @RequestScoped
  public class BookBean implements Serializable
  {
      @EJB
      private BookService bookService;
  
      @ManagedProperty(value = "#{param.id}")
      private Long id;
  
      private DataModel&lt;BookModel&gt; books;
      private BookModel currentBook;
  
      @PostConstruct
      public void init() {
          currentBook = bookService.find(id);
      }
  
      public BookModel getCurrentBook() {
         return currentBook;
      }
  
      public void setCurrentBook(BookModel currentBook) {
         this.currentBook = currentBook;
      }
   }
  </code></pre>
  
  <p>Running the BookBean class above caused this error: <code>java.lang.IllegalStateException: WEB9031: WebappClassLoader unable to load resource [org.apache.openjpa.util.LongId], because it has not yet been started, or was already stopped</code>. This is where I'm stuck at the moment.</p>
  
  <p>FYI: My dev environment is Glassfish 3.1, Apache OpenJPA 2.1 and JSF 2.1.0 (that comes bundled with Glassfish)</p>