Fixed: How to remember the DataTable state and still use buttons

Lets say that you have a DataTable on a page, with a bunch of hyper links and buttons on the same page (for navigation to various parts of your application). If you use the built in pagination and sorting, you will find that the following behaviour:

1. DataTable remembers its state (sorting, page number, etc.) if you click on any hyper link. You can even go back to a different page, and then come back to the original page to find that your DataTable is in the state you left it (very cool, it is session scope and works as intended).

2. If you click on any button, DataTable does not remember its previous state (goes back to page 1 and default worting, etc.). After playing around with it and going nuts, I discovered the way to use Button and still have the DataTable remember its state. I wanted to share it with the rest of you:

public String btnClose_action(){

try{

this.getExternalContext().redirect("faces/users.jsp");

}catch (Exception ex){

log("Error: userDetail > btnClose_action", ex);

}

returnnull;

}

This was my original post:

http://swforum.sun.com/jive/thread.jspa?threadID=103583

Message was edited by:

Sabir

[1599 byte] By [Sabir] at [2007-11-26 10:55:52]
# 1
That's interesting - "faking" a button action in order to execute a hyperlink-type action.I wonder if this is what Hyperlink is doing under the hood?Why does DataTable preserve its state with Hyperlink, but not Button (or other) action components?
utsukushii at 2007-7-7 3:09:02 > top of Java-index,Development Tools,Java Tools...
# 2
I have been told that buttons submit the data and that is why the DataTable is not preserved. In the app, I do need a button (due to its look and feel), not a hyperlink. I think there should be a property to disable form submission on buttons. Any how, this work around is working very
Sabir at 2007-7-7 3:09:02 > top of Java-index,Development Tools,Java Tools...
# 3
I tried this solution and it didn't work.Is there a secret to getting this to work?My table reverted right back to page 1 every time. I am trying to preserve the table numbers when I navigate to different pages.
winderjj at 2007-7-7 3:09:02 > top of Java-index,Development Tools,Java Tools...
# 4

>II think there should be a property

> to disable form submission on buttons.

There is!

To make the form not be submitted by a button click:

1. In the Visual Designer, select the button.

2. In the Properties window set the JavaScript > onClick property to return false;

This might interest you: http://blogs.sun.com/divas/entry/disabling_a_button_after_it

jetsons at 2007-7-7 3:09:02 > top of Java-index,Development Tools,Java Tools...