setting/adding two fragments on button click?

I’m trying to save the state of a form as it was right when the submit button is clicked (after any edits since the user first visited the page) into browser history as a unique fragment (different from that of the form when first visited), but I’m having a problem. I’m using the fragment utility to do this, by generating a code (number) to represent the form state, and then setting the fragment to include that new code in response to the “submit” button. The idea is that the user can go back to their last edits from the results page, or further to the form as it originally was before that, and so on. This would be great, rich history for the user so I hope I don’t have to give up on this feature.

BUT. The submit button is supposed to also trigger showing results which has its own fragment, and that’s the problem. I need to set (add to browser history) two fragments in then one event response to the submit button being clicked, which is not working. I believe one can’t set two fragments in one back/forth with the server - only the second fragment (the results page) actually goes into browser history, the first (final form state) fragment never makes it into browser history. Is there some easy way to do this?

Here’s an overview of what I’m trying which isn’t working (final form state fragment doesn’t go into browser history):

#form-0 (initial form state)

(user does some edits)

final form state stored as “form-1”

set fragment #form-1 <== No effect

add results components

set fragment #results-1

(browser now has only #form-0 and #results-1, not #form-1)

Any ideas how to add two browser history items in one event handling trip, or whether this is indeed the problem?

Using Vaadin 6.5.1.

Thank you!
Steve Harris

Fragments are managed by the client on browser side. So for the client to know what fragment it should set and when it should be set you need to do a round trip per new fragment.

Thanks Clerc, this is what I suspected about using the fragment utility class.

It would be nice if the fragment utility could keep a list of fragment updates internally instead of a single member and set each one in sequence on the client after the server event handling. I don’t know how common that requirement is though.

In any case, I was able to solve the problem very simply however by just relying on javascript to set the fragments:

private void setFragment(String frag)
mainWindow.executeJavaScript(“location.hash = '” + frag + “'”);

Multiple fragment changes can be stacked up by repeated calls to this method, and they do always seem to execute in the proper order (not sure if that’s documented of executeJavaScript() but it seems reasonable that it would execute the JS in the order received). It seems to work well on Firefox 8 at least, I still need to test on other browsers though.