3

I am building something that I want to work something like Google Maps. As your state changes, the URL in the address bar changes. You can later on copy & paste this URL and come back to it.

I am conditionally rendering outputPanels based on radio button values and then putting their IDs as window.history.pushState(panelId, button.value, document.URL+'/'+button.value);

So after few dialogs my URL looks like 'apex/page/mens/shoes/8/' and so on.

Is there a way to construct my controller / URL rewrite class so that based on URL it would return certain JavaSript code that would traverse thru steps?

I may consider later on to do something to actually save the state to a record on SF.

Edit: So I am looking at this video, and looks like you can return basically anything from URL rewriter, not necessarily a specific record. Did anyone try this before? Also, is there a way to test URL rewriter class without actually setting up a new site?

1 Answer 1

2

Yes, you can easily do what you want to do with a rewriter. You'd do something like map all URL's beginning with /apex/page[/blah] to /apex/page?state=[/blah]. Then your controller would pass the state param to JS in a way that JS can deal with it. Doing that should be quite easy but will be specific to how you're dealing with state in JS.

I've done several implementations where arbitrary URLs are mapped to various pages with commands/state embedded in the URL, so I know this is easy.

Just make sure your page state can't get so long after a lot of clicking that it's no longer appropriate for a URL, but that's not a VF-specific problem.

You can do unit tests on a UrlRewriter, but you can't really properly test it without an active site/community. You can provision sites from sandbox, developer, and trial orgs (probably have to raise a case for trial orgs), so you should be able to test this as you need.

1
  • Yep that worked for me!
    – dzh
    Commented May 25, 2015 at 4:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .