Different behavior: Hyperlink vs Button, please advice
I have a "Customers" page, that lists all customers using Data Table bound to a customerDataProvider. User can click on the first column to go to "Customer Detail" page, which has its own data Provider and provides more details about the specific customer. So far so good.
In the "Customer Detail" page, I added a "Close" button and a "Close" hyperlink (to test). The purpose of these is to close the detail page and to go back to "Customers" page. Simple, right.
This is what I found:
When you click on the close hyperlink in the detail page, it goes back to the master page (Customer page), and the master page remembers its state (page number, sorting, etc.)
When you click on the button (I tried both ui:button and h:commandButton), the master page goes back to its default state and it does not remember its state.
I would like to use the button and have the page remember its state. Why are they behaving different? Any insights?
[973 byte] By [
Sabir] at [2007-11-26 9:34:25]

# 1
I guess you specified hyperlink's url property to navigate to the master page. In this case, page is not submitted. If you use hyperlink's action or create navigation link in navigation editor. You will see the same behaviour as button.
To keep master page state, use session bean or request bean. Please refer
the boundled sample app Corporate Travel Center.
# 2
So, I have two choices:
1. Disable "Submit" on the "Close" button - since its just a link and it doesn't need to submit. But I can't figure out how to disable submit and make the button act like a hyperlink.
2. Use session bean to store the table state. I just tried this one to save sorting and it worked, but I need to save all other parameters of table state, like page number, records per page, filtering, etc. Is there just one function that I can call to store all these, or do I need to save each one seperately?
In session bean:
// Save the sort critera of a data table - MS
private TableDataSorter tableDataSorter;
public void setTableDataSorter(TableDataSorter tableDataSorter){
this.tableDataSorter=tableDataSorter;
}
public TableDataSorter getTableDataSorter(){
return this.tableDataSorter;
}
In preRender of master page:
public void prerender() {
info("Page="+this.getTableRowGroup1().getPage());
if (getSessionBean1().getTableDataSorter()!=null){
this.getTableRowGroup1().setTableDataSorter(getSessionBean1().getTableDataSorter());
}
//web_userDataProvider.refresh();
}
Is there a better way to do this or this is the best we can do?
Sabir at 2007-7-7 0:23:34 >

# 3
> 1. Disable "Submit" on the "Close" button - since its
> just a link and it doesn't need to submit. But I
> can't figure out how to disable submit and make the
> button act like a hyperlink.
Have you tried the image hyperlink? With an image that looks like a button. :-)
Juergen
# 4
No, but its a good tip.
Now I am thinking to save the table state (page number, sorting, etc.) in a session bean because I also have edit and save buttons on the detail page to allow user editing and saving changes. After the changes are saved, I would like the close button to take them back to master table, but on the same page number and sorting state that they were before opening the detail page.
Sounds like this should be a very common use in most web apps. I have not seen it discussed as much. How do other people get around this?
Sabir at 2007-7-7 0:23:34 >
