How do i solve A datatable problem in JSF

Posted by Nitesh Panchal on Stack Overflow See other posts from Stack Overflow or by Nitesh Panchal
Published on 2010-05-06T07:43:28Z Indexed on 2010/05/06 7:48 UTC
Read the original article Hit count: 245

Filed under:
|

I have a databale on index.xhtml

     <h:dataTable style="border: solid 2px black;"
                                 value="#{IndexBean.bookList}" var="item"
                                 binding="#{IndexBean.datatableBooks}">

  <h:column>
                        <h:commandButton value="Edit" actionListener="#{IndexBean.editBook}">
                            <f:param name="index" value="#{IndexBean.datatableBooks.rowIndex}"/>
                        </h:commandButton>
                    </h:column>
 </h:dataTable>

My bean :-

@ManagedBean(name="IndexBean")
@ViewScoped
public class IndexBean implements Serializable {
  private HtmlDataTable datatableBooks;

 public HtmlDataTable getDatatableBooks() {
    return datatableBooks;
}

public void setDatatableBooks(HtmlDataTable datatableBooks) {
    this.datatableBooks = datatableBooks;
}

 public void editBook() throws IOException{
        int index = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("index").toString());
        System.out.println(index);


    }
}

My problem is i always get the same index in server log even though i click the different edit buttons, Imagine that there is one collection which is supplied to the datatable. I have not shown that in bean.

If i change scope from ViewScope to RequestScope it works fine. What can be the problem with @ViewScoped? Thanks in advance :)

© Stack Overflow or respective owner

Related posts about jsf

Related posts about facelets