Friday, December 19, 2008

JSF / JBossSeam - Show list of records with scroller & Return to the page from which you edited.




The above content is emplist.xhtml.
Consider the scenario, Requirement 1 : Display a list of employee records as 10 rows per page. Requirement 2: You are editing a record of employee list in n-th page. On clicking on save or cancel button, it has to go the n-th page from which you edited. In JSF/Seam, We have dataTable and dataScroller components from richfaces to achieve these.

Use rich:dataTable to list the employee records as above.

Use rich:dataScroller to have scroller for the table.
Use for attribute to map the table.

Use pageIndexVar attribute of rich:datascroller to capture the current page number and pass it as request parameter while editing the record.

Retrieve the page index value from request and calculate the first row to be displayed in dataTable as below:

//Get the request parameter pageIndex
Integer index = Integer.parseInt((String)FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("pageIndex"));

//Calculate the first row to set into the first attribute of rich:dataTable
index = (index - 1) * 10; // 10 – value of rows attribute in rich:dataTable


Set this value in session scope.

While clicking the save or cancel button, get the index value from session and set the value to member variable bound to the first attribute of rich:dataTable.

4 comments:

  1. Srini,
    I would say it's a good effort. Don't ever attach code as image as it could be very frustrating for developers if you stop them from Ctrl + c & Ctrl + v. Otherwise keep writing, i am following your blog too...

    ReplyDelete
  2. Senthil,

    Sorry for the inconvenience.
    But i'm not able to write jsp/jsf codes as blogspot using html editor to post the blogs.
    So, Attached the jsf code as image.

    Tips/suggestions to write jsp/jsf codes are welcome.

    ReplyDelete
  3. For useful Java coding techniques,

    http://smartjavasrini.blogspot.com/

    :)

    ReplyDelete